问题
VBA - SQL Server 2014 - How to access localhost?
Pretty much, I need to access localhost of SQL Server and I have tried almost anything I found here:
What is the sql connection string I need to use to access localhost\SQLEXPRESS with Windows Authentication or SQL Authentication?
I have tried this:
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;"
And both return error:
This is a German Run-Time error, saying something about OLE DB. (My German is also not in my top 4 languages).
I want WindowsAuthetication. The automatic one, without username or password.
So what are the ideas? I use MSSQL Management Studio 2014. ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
A day has passed. this is what I tried in the morning: @GuidoG I liked the idea, but I did not succeed to make it in a way. What should be the servername on the top (point 1), in order to find my DB (point 3)?
@Comintern The local server, to which I am connecting through the MS DB Studio looks like this:
(localdb)\MSSQLLocalDB
Edit: I am trying to connect to localhost.
回答1:
Try stating the driver like the below in the VBA connection string. You will find server\instance right below the connect bar (in object explorer) in SSMS.
"SERVER=[server]\[instance];DRIVER={SQL Server};Initial Catalog=[database];Trusted_Connection=Yes"
回答2:
Actually this is what has worked for me:
connectionString = "Provider=SQLNCLI11;Server=(localdb)\MSSQLLocalDB;Initial Catalog=Tempt;Trusted_Connection=yes;timeout=30;"
My db is named "Tempt". I have taken the code from here: https://sysmod.wordpress.com/2014/07/11/adodb-connection-string-for-localdb-and-sql-server-native-client/
Thanks everyone for the help! :)
来源:https://stackoverflow.com/questions/39352727/vba-sql-server-2014-how-to-access-localhost-windows-authentication