我是SQL和VBA的新手.我编写了一个SQL查询,我希望能够从excel工作簿中的VBA子句调用和运行,然后将查询结果带入工作簿.我发现了一些在线(stackoverflow和其他地方)声称这样做但我无法理解它们,因为它们没有任何解释.例如,这是我在网上找到的一个子:
Sub ConnectSqlServer()
Dim conn As ADODB.Connection
Dim rs As ADODB.Recordset
Dim sConnString As String
' Create the connection string.
sConnString = "Provider=SQLOLEDB;Data Source=INSTANCE\SQLEXPRESS;" & _
"Initial Catalog=MyDatabaseName;" & _
"Integrated Security=SSPI;"
' Create the Connection and Recordset objects.
Set conn = New ADODB.Connection
Set rs = New ADODB.Recordset
' Open the connection and execute.
conn.Open sConnString
Set rs = conn.Execute("SELECT * FROM Table1;")
' Check we have data.
If Not rs.EOF Then
' Transfer result.
Sheets(1).Range("A1").CopyFromRecordset rs
' Close …Run Code Online (Sandbox Code Playgroud) 在SQL Server连接字符串中,Integrated Security = True/SSPI和之间有什么区别Persist Security = True?
我刚刚将数据库备份恢复到本地SQL Server Express实例.
当我尝试登录时,日志中给出了以下错误:
用户'用户名'登录失败.原因:找不到与提供的名称相匹配的登录信息.[客户:]
如何让SQL Server找到与我提供的名称相匹配的登录名?
其他信息:
我有一个数据库,我创建了一个包含用户,我需要使用该用户连接到我的Web应用程序.我一直能够与标准用户连接到Web应用程序Persist Security Info=False.
但是,我能够与所包含的用户连接的唯一方法是将我的连接字符串更改为Persist Security Info=True,否则即使我能够使用SSMS连接,我也会获得登录失败的sql异常.我不确定它为什么会起作用,是否有人知道为什么包含的用户需要将属性设置为True?