0
votes

The error is shown as below:

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified) Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)

Source Error:

Line 69: public Boolean UserAuthentication(string UserID, string Password)

Line 70: {

Line 71: Con.Open(); // Red Color - showing this is the error.

Line 72:

Line 73: SqlCommand cmd = new SqlCommand("SELECT * FROM LoginList WHERE UserID = '" + UserID + "' AND Password = '" + Password + "'", Con);

My Connection string was written as below:

static SqlConnection Con = new SqlConnection(
     @"Data Source=.\SQLEXPRESS;
     AttachDbFilename=|DataDirectory|\Database.mdf;
     Integrated Security=True;
     User Instance=True");

Note: Firewall service is disable and SQL server name no error.

1

1 Answers

0
votes

Try like this,

static SqlConnection Con = new SqlConnection(
 @"Data Source=.\SQLEXPRESS;
 Initial Catalog=Database.mdf;
 Integrated Security=True;
 User Instance=True");