0

I am getting below exception while connecting ASP.NET with SQLSERVER using below connection strings.i tried two methods.

Exception

An exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll but was not handled in user code

Additional information: 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

Connection String

    protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con;
            con = new SqlConnection("Server=ADMIN/SQLEXPRESS,Database=test,integrated security=true");
            con.Open();

        }

              (or)

    protected void Page_Load(object sender, EventArgs e)
        {
            SqlConnection con;
            con = new SqlConnection("Server=localhost;Database=test;integrated security=sspi");
            con.Open();

        }

i am connecting SQLSERVER directly by using below server name in windows authentication.It is connecting well but it is not connected from asp.net

Server Name:ADMIN\SQLEXPRESS

4
  • 1
    Possible duplicate of Why am I getting "Cannot Connect to Server - A network-related or instance-specific error"? Commented May 30, 2019 at 14:49
  • 2
    Remember that IIS (and IISExpress too) runs using a different user than yourself Commented May 30, 2019 at 14:52
  • Your top connection string is mangled: uses / not \, uses commas not semicolons. Your bottom connection string is mangled - doesn't cite an instance name, required for SQL Express Commented May 30, 2019 at 15:04
  • try this connectionString="Data Source=localhost;Initial Catalog=YourDataBaseName;Integrated Security=True;" Commented May 30, 2019 at 15:41

1 Answer 1

1

A connection string for SQL server should be like this: "Server=localhost; Database=Testdb; Integrated Security=True;" and If you have Named Instance e.g localhost\SQLEXPRESS

Integrated Security=?

When false, User ID and Password are specified in the connection. When true, the current Windows account credentials are used for authentication. Recognized values are true, false, yes, no, and SSPI (strongly recommended), which is equivalent to true.check connectionstrings

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.