2008年3月16日

Connecting Sql Server 2005 Express by Excel 2003 VBA

記錄 Excell 2003 連接 Sql Server 2005 Express 的 connection string

IDE: Excell 2003 VBA
OS: Windows XP Professional
DB Server: Sql Server 2005 Express (安裝於本機)

在 Excell 2003 VBA 開發環境中,於[工具]->[設定引用項目]->選擇 Microsoft [ActiveX Data Object 2.8 Library] 引用 ADO 物件。連線的 Provider 使用 SQL Native Client。

Sql Server 2005 Express 驗證方式使用 Windows 驗證。

範例如下
Dim conStr As String

conStr = "Provider=SQLNCLI.1;" & _
"Integrated Security=SSPI;" & _
"Persist Security Info=False;" & _
"Initial Catalog=xxx;" & _
"Data Source=local\sqlexpress"

' xxx 表資料庫名稱
' local 表本機