VBA - SQL Server 2014 - 如何访问本地主机 - Windows 身份验证

VBA - SQL Server 2014 - How to access localhost - Windows Authentication

VBA - SQL Server 2014 - 如何访问本地主机?

差不多,我需要访问 SQL 服务器的本地主机,我已经尝试了在这里找到的几乎所有内容:

What is the sql connection string I need to use to access localhost\SQLEXPRESS with Windows Authentication or SQL Authentication?

我试过这个:

    str_connection_string = "Data Source=localhost\SQLEXPRESS;Initial Catalog=Tempt;Integrated Security=True;"
    str_connection_string = "Data Source = .\\SQLEXPRESS;Initial Catalog=Tempt;Integrated Security=True;"

并且都return错误:

这是德语 运行-Time 错误,说了一些关于 OLE DB 的事情。 (我的德语也不在我的前 4 种语言之列)。

我想要 WindowsAuthetication。自动的,没有用户名或密码。

那么有什么想法呢? 我使用 MSSQL Management Studio 2014。 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ++++++++++++++++++++

一天过去了。这是我早上试过的: @GuidoG 我喜欢这个想法,但我没有成功地以某种方式实现它。为了找到我的数据库(第 3 点),顶部的服务器名称(第 1 点)应该是什么?

@共产国际 我通过 MS DB Studio 连接到的本地服务器如下所示:

(localdb)\MSSQLLocalDB

编辑:我正在尝试连接到本地主机。

尝试在 VBA 连接字符串中像下面这样声明驱动程序。您会在 SSMS 中的连接栏(在对象资源管理器中)的正下方找到 server\instance。

"SERVER=[server]\[instance];DRIVER={SQL Server};Initial Catalog=[database];Trusted_Connection=Yes"

实际上这对我有用:

connectionString = "Provider=SQLNCLI11;Server=(localdb)\MSSQLLocalDB;Initial Catalog=Tempt;Trusted_Connection=yes;timeout=30;"

我的数据库名为 "Tempt"。 我从这里获取了代码: https://sysmod.wordpress.com/2014/07/11/adodb-connection-string-for-localdb-and-sql-server-native-client/

感谢大家的帮助! :)