[英]C#-Error 26- Locating Server/Instance Specified
I am attempting to run a program that gets data from a remote SQL Server, but when I run the program the debugger says "Error Locating Server/Instance Specified" 我试图运行一个从远程SQL Server获取数据的程序,但是当我运行该程序时,调试器显示“错误定位服务器/实例已指定”
I searched the web and Stack Overflow and tried many things, but nothing worked! 我在网上搜索了Stack Overflow,并尝试了很多方法,但是没有任何效果!
What am I doing wrong here? 我在这里做错了什么?
private void txtsearch_Click(object sender, EventArgs e)
{
SqlConnection conn = new SqlConnection("Server=.\\MSSQLSERVER;AttachDbFilename = C:\\Program Files\\Microsoft SQL Server\\MSSQL11.MSSQLSERVER\\MSSQL\\DATA\\Education.mdf; Database= education;Trusted_Connection=Yes;");
DataTable dt = new DataTable();
SqlDataAdapter SDA = new SqlDataAdapter("Select * From Education Where NationalKey "+ txtNationalKey.Text, conn);
SDA.Fill(dt);
dataGridView1.DataSource = dt;
}
I tried MSSQL11,SQL Express and many other format of string. 我尝试了MSSQL11,SQL Express和许多其他格式的字符串。 I opened UDP port 1434,TCP port 1433 and 7200 too.
我也打开了UDP端口1434,TCP端口1433和7200。
.\\\\
in your connection string refer to local machine. 连接字符串中的
.\\\\
是指本地计算机。 Set Ip or machine name of the SqlServer machine. 设置ip或SqlServer计算机的计算机名称。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.