riachan
riachan

Reputation: 51

Connection string using local SQL Server

How to write the connection string to local SQL Server database using web.config?

Here is my connection string in web.config. But when I open local/demo, it said:

login failed for user ''.

Actually I'm using Windows authentication, so I thought it doesn't need user and password.

<connectionStrings>
    <add name="HRISContext" 
         connectionString="data source=.;initial catalog=BPSDEMO;Pooling=false;persist security info=True;user id=;password=;MultipleActiveResultSets=True;App=EntityFramework" 
         providerName="System.Data.SqlClient"  />
</connectionStrings>

Upvotes: 0

Views: 4952

Answers (1)

marc_s
marc_s

Reputation: 754478

If you want to use Windows authentication, then yes, you must not include any user id and pwd in your connection string - just remove those completely. But you must include the Integrated Security=SSPI setting instead.

Try this:

<connectionStrings>
    <add name="HRISContext" 
         connectionString="data source=.;initial catalog=BPSDEMO;Integrated Security=SSPI;MultipleActiveResultSets=True;Pooling=false;persist security info=True;App=EntityFramework" 
         providerName="System.Data.SqlClient"  />
</connectionStrings>

Upvotes: 1

Related Questions