简体   繁体   English

无法连接到SQL Server 2012

[英]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. 我正在尝试使用C#连接到SQL Server 2012数据库,服务器和程序都在同一台计算机上。 When I try to connect I get an exception: 当我尝试连接时,出现异常:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. 建立与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. 验证实例名称正确,并且已将SQL Server配置为允许远程连接。 (provider: SQL Network Interfaces, error: 25 - Connection string is not valid) (提供者:SQL网络接口,错误:25-连接字符串无效)

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. 我有一个名为logger的SQL登录名,该登录名与密码相同,并且已映射到数据库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) 我相信应该是(localdb)而不是(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");

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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