[英]Trying to connect to SQL Server on Visual Studio
I have a little silly program to test a Connection to a database on SQL Server 2014, I'm using c# on Visual Studio 2015.我有一个愚蠢的程序来测试与 SQL Server 2014 上的数据库的连接,我在 Visual Studio 2015 上使用 c#。
First I tested it on my PC, it works wonderful!首先我在我的电脑上测试了它,它工作得很好! then I moved to my laptop.
然后我搬到了我的笔记本电脑上。 I did a little mistake while installing SQL 2014 because I installed the manager before installing the other Express version... but when I created the database It worked so I thought it was not a problem.
我在安装 SQL 2014 时犯了一个小错误,因为我在安装其他 Express 版本之前安装了管理器……但是当我创建数据库时它工作正常,所以我认为这不是问题。
But when I tested the connection in my laptop it fails!但是当我在笔记本电脑上测试连接时,它失败了! every time I try, I started all SQL services, I created an string connection but in the field where is supposed to be the name of the server it doesn't displays anything.
每次尝试时,我都启动了所有 SQL 服务,创建了一个字符串连接,但在应该是服务器名称的字段中,它不显示任何内容。 So I tried using "."
所以我尝试使用“。” as the name of the server and my database appeared, so I created the string connection and it says it is "connected".
由于服务器和我的数据库的名称出现,所以我创建了字符串连接,它说它是“连接的”。
I'm really desperate because it works perfectly on my PC but on my laptop it just fails.我真的很绝望,因为它在我的 PC 上运行良好,但在我的笔记本电脑上却失败了。
Here is the code for the string, I have tested every name I see on SQL Server ( Julia, Julia-Fer, Julia\\Fer, even .\\SQLEXPRESS)这是字符串的代码,我测试了我在 SQL Server 上看到的每个名称(Julia、Julia-Fer、Julia\\Fer,甚至 .\\SQLEXPRESS)
System.Data.SqlClient.SqlConnection conn =
new System.Data.SqlClient.SqlConnection();
// TODO: Modify the connection string and include any
// additional required properties for your database.
conn.ConnectionString = "integrated security=SSPI;data source=.\\SQLEXPRESS;" +
"persist security info=False;initial catalog=Proyecto";
I'm using Visual Studio 2012 on PC and 2015 on my laptop.我在 PC 上使用 Visual Studio 2012,在笔记本电脑上使用 2015。
将您的连接字符串更改为
conn.ConnectionString = "data source=.\\SQLEXPRESS;initial catalog=Proyecto;persist security info=False;integrated security=true";
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.