Excel VBA - 使用受信任的连接(无 uid/pwd)连接到 sql

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1573725/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-01 04:00:43  来源:igfitidea点击:

Excel VBA - connect to sql with a trusted connection (no uid/pwd)

sqlexcelvbaconnection-stringadodb

提问by notnot

Is there a way to have Excel connect to Sql Server using the current user's network windows authentication (trusted connection/integrated security)? I don't want to rely on a sql login or have a uid/password in my code.

有没有办法让 Excel 使用当前用户的网络 Windows 身份验证(可信连接/集成安全)连接到 Sql Server?我不想依赖 sql 登录或在我的代码中使用 uid/密码。

回答by El Ronnoco

I have this connectionstring in an Excel 2003 VBA project...

我在 Excel 2003 VBA 项目中有这个连接字符串...

"Provider=SQLOLEDB;Data Source=[You DB Name];Trusted_connection=yes;"

And it works for me! (I'm using ADODB)

它对我有用!(我正在使用 ADODB)

回答by Cade Roux

Driver={SQL Native Client};server=servernamehere;database=dbnamehere;Trusted_Connection=yes;

http://www.sqlstrings.com/SQL-Server-connection-strings.htm

http://www.sqlstrings.com/SQL-Server-connection-strings.htm

http://www.connectionstrings.com/sql-server

http://www.connectionstrings.com/sql-server

Try this one:

试试这个:

Provider=sqloledb;Data Source=myServerName;Initial Catalog=myDatabaseName;Integrated Security=SSPI

回答by Tomalak

See: http://www.connectionstrings.com/

请参阅:http: //www.connectionstrings.com/

Especially http://www.connectionstrings.com/sql-server-2005, for example:

尤其是http://www.connectionstrings.com/sql-server-2005,例如:

Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

or any other suitable connection string you find there.

或您在那里找到的任何其他合适的连接字符串。

回答by Stefan Michev

Working sample for VBA Excel 2010

VBA Excel 2010 的工作示例

Provider=SQLOLEDB;Data Source=ServerIPOrName;Initial Catalog=DatabaseName;Trusted_connection=yes;

Provider=SQLOLEDB;Data Source=ServerIPOrName;Initial Catalog=DatabaseName;Trusted_connection=yes;