- ©«¤l
- 41
- ¥DÃD
- 8
- ºëµØ
- 0
- ¿n¤À
- 64
- ÂI¦W
- 0
- §@·~¨t²Î
- WIN7
- ³nÅ骩¥»
- OFFICE2010
- ¾\ŪÅv
- 20
- µù¥U®É¶¡
- 2015-3-11
- ³Ì«áµn¿ý
- 2020-10-7
|
·íµM¥i¥H
°Ñ¦Ò³oÃ䪺»¡©ú "tomliu888.blogspot.tw/2016/04/excel-ms-sql-vba.html"
¦]¤£¯à¶K³sµ², ©Ò¥H§â¤º®e¶K¤W¨Ó
Sub connectSQL()
Dim Conn As ADODB.Connection
Dim sConnect As String
Dim strSqlInstance As String
Dim strSqlDB As String
Dim strSqlUser As String
Dim strSqlPWD As String
' strSqlInstance = "SERVER_NAME\INSTANCE"
' ¦pªG¦øªA¾¹¥u¦³¸Ë¤@¦¸ SQL¡A´N¥un¿é¤J¦øªA¾¹¦WºÙ
strSqlInstance = "Your SQL Server Name or IP Address"
strSqlDB = "Your Database Name"
strSqlUser = "sa"
strSqlPWD = "password"
sConnect = "Provider=SQLOLEDB"
sConnect = sConnect & ";DATA SOURCE=" & strSqlInstance & ";Initial Catalog=" & strSqlDB
' ¦pªG§â User ID=...;Password=... §ï¦¨ "Integrated Security=sspi;"¡A»{ÃҤ覡´NÅܦ¨ AD µn¤J±b¸¹
sConnect = sConnect & ";User ID=" & strSqlUser & ";Password=" & strSqlPWD & ";"
Set Conn = New ADODB.Connection
Conn.ConnectionString = sConnect
Conn.Open
' ³o¸Ì¿é¤J§A³B²z SQL ªº©R¥O
Conn.Close
End Sub |
|