我想在 Excel vba 中从 SQL Server 访问/检索/创建记录集。
我尝试了以下方法,但它们返回错误。
代码 1:
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConnString As String
sConnString = "Provider=sqloledb; Server=192.168.0.204; Database=REPORTdb2"
Set Conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open sConnString
Set rs = conn.Execute("select * from Table1;")
在该行conn.Open sConnString
发生错误:
无效的授权规范
代码2:
sConnString = "Provider=SQLOLEDB;Data Source=192.168.0.204;" & _
"Initial Catalog=ReportDB2;" & _
"Integrated Security=SSPI;"
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
conn.Open sConnString
Set rs = conn.Execute("SELECT * FROM Table1;")
它抛出一个错误
无法生成 SSPI 上下文