使用C#连接SQL 报错:无法连接

来源:互联网 发布:java回调机制是异步 编辑:程序博客网 时间:2024/05/21 10:59

如果用(local)\sqlexpress登陆的数据库,C#连接字符串怎么写?

string connString = @"Data Source=localhost\SQLEXPRESS;Initial Catalog=Test;Integrated Security=True";

nitial Catalog=Test; 就是初始选择哪一个数据库, 我这里是 Test ,

Data Source=localhost\SQLEXPRESS; 我这个是 SQL Server Express 版本的, 因此是这个地址。 如果你安装的是正式版本的, 那就是
Data Source=localhost

 

最初我将Data Source写成localhost\SQLEXPRESS,结果无法连接,改为Data Source=localhost就可以了!

 

0 0