如何调试此数据库连接字符串?

时间:2017-03-11 02:59:43

标签: asp.net-mvc-4

SqlConnection con = new SqlConnection("Server=ACER-PC/SQLEXPRESS;Database=coupon;Integrated Security=true");

这有什么不对?

2 个答案:

答案 0 :(得分:0)

SQL Server的连接字符串应该更像:“Server = localhost; Database = employeedetails; Integrated Security = True;”

如果您有一个SQL Server的命名实例,您还需要添加它,例如“Server = localhost \ sqlexpress”。

如果不是Windows身份验证,那么连接字符串将如下所示, Data Source = ServerName; Initial Catalog = DatabaseName; User ID = UserName; Password = Password“;

答案 1 :(得分:0)

试试这个

在网络配置文件中添加此代码

 <connectionStrings>
<add name="ProjectConnectionString" connectionString="Data Source=ACER-PC/SQLEXPRESS OR Your system ip address;Initial Catalog=coupon;Integrated Security=false;user=username;password=password"/> 
</connectionStrings>

然后初始化你的连接字符串,如

SqlConnection cn = new SqlConnection(ConfigurationManager.ConnectionStrings["ProjectConnectionString"].ToString());