今天看个例子程序,程序里面的数据库连接字符串如下:
Data Source=localhost;Initial Catalog=Store;User Id=sa;Password=password
运行程序以后发现连接不到数据库。
上网查了查,发现了问题的原因:
我使用的数据库是SQL Server Express,在SQL Server Express中连接字符串应该如下:

Data Source=server\SQLEXPRESS;Initial Catalog=Store;User Id=sa;Password=password

其中server是计算机名。

使用Windows登陆的帐户,则为:

 

 

Data Source=server\SQLEXPRESS;Initial Catalog=Store;
Integrated Security=SSPI

 

不使用远程连接的时候应该把连接字符串改为:
 Data Source=localhost\SQLEXPRESS;Initial Catalog=Store;
Integrated Security=SSPI

 

 

posted on 2009-10-07 20:06  pdfw  阅读(1122)  评论(0编辑  收藏  举报