简体   繁体   中英

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"

I searched the web and Stack Overflow and tried many things, but nothing worked!

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. I opened UDP port 1434,TCP port 1433 and 7200 too.

.\\\\ in your connection string refer to local machine. Set Ip or machine name of the SqlServer machine.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM