简体   繁体   中英

Connecting SQL Server with ASP.NET using Windows Authentication

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

A connection string for SQL server should be like this: "Server=localhost; Database=Testdb; Integrated Security=True;" and If you have Named Instance eg 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

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