简体   繁体   中英

Cannot connect to SQL Server 2012

I'm trying to connect to a SQL Server 2012 database using C#, both the server and program are on the same computer. When I try to connect I get an exception:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 25 - Connection string is not valid)

There is an inner exception simply saying {"The parameter is incorrect"}.

I'm trying to connect using this

SqlConnection sql = new SqlConnection("Server=(local)\\MSSQLSERVER;Database=Test;User ID=logger;Password=logger;Trusted_Connection=False");
sql.Open();

I have a SQL login called logger with the same text as the password and it is mapped the database Test. I believe I have the server set up to take remote logins.

Any ideas as to what I am missing?

I believe it should be (localdb) rather than (local)

connectionstrings

The error message does state (at the end):

Connection string is not valid

so you need to check it at the linked page.

Try

SqlConnection sql = new SqlConnection("Server=.;Database=Test;User ID=logger;Password=logger;Trusted_Connection=False");

Or

SqlConnection sql = new SqlConnection("Server=local;Database=Test;User ID=logger;Password=logger;Trusted_Connection=False");

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM