我在一台计算机上安装了2008 SQL Server Express,并且尝试建立远程连接...使用MS SQL Server Management Studio时,我可以毫无问题地登录数据库(相同凭据),但是当我尝试在C#应用程序中创建连接字符串时,出现异常:
这是我的连接字符串的样子(私有(private)信息已更改):
"Data Source="MACHINENAME\\SQLEXPRESS";User ID="Admin";Password="the_password";Initial Catalog="MyDatabase";Integrated Security=True;Connect Timeout=120");
如我所说,我可以使用Management Studio以相同的设置登录:相同的用户ID,密码和数据源名称,但是当我尝试使用上述连接字符串打开连接时,它失败。
笔记:
有人可以告诉我我做错了什么吗?
更新,这是我的确切代码(这次仅删除密码,并且我添加了在同一台计算机上运行的Management Studio的图片):
string _connectionString =
//string.Format("Server=%s;User ID=%s;Password=%s;Database=%s;Connect Timeout=120", // Same problem
//string.Format("Server=%s;User ID=%s;Password=%s;Database=%s;Integrated Security=False;Connect Timeout=120", // Same problem
string.Format("Data Source=%s;User ID=%s;Password=%s;Initial Catalog=%s;Integrated Security=False;Connect Timeout=120", // Same problem
"GANTCHEVI\\SQLEXPRESS",
"FinchAdmin",
"the_password",
"Finch");
Connected Via Management Studio: See Picture http://s113.photobucket.com/albums/n202/ozpowermo/?action=view¤t=ManagementStudio.jpg
http://s113.photobucket.com/albums/n202/ozpowermo/?action=view¤t=ManagementStudio.jpg
我想出来了:
当使用“数据源=”标签时,应使用“用户ID”,如果您使用用户ID,它似乎不起作用!
string _connectionString = "Data Source=GANTCHEVI\\SQLEXPRESS;Initial Catalog=Finch;Integrated Security=False;User Id=FinchAdmin;Password=the_password;Connect Timeout=0";"
最佳答案
从连接字符串中删除Integrated Security = True,然后(可选)添加Persist Security Info = True;
从MSDN:
关于c# - C#2008 SQL Server Express连接字符串,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/997169/