简体   繁体   中英

Why ASP.NET site doesn't connect to SQL Server database,using SQL Server authentication?

I created a database in SQL Server 2012 Express. The default login to the server through authenticated Windows, but during the installation set up the possibility of authentication SQL Server. Added the .mdf file to the ASP.NET MVC site, connect it via the connection string - all is well.

Connection string:

<add name="GnrlBase" 
     connectionString="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\articlesbase2.mdf;Integrated Security=true;MultipleActiveResultSets=True;App=EntityFramework" 
     providerName="System.Data.SqlClient" />    

I decided to change the authentication - SQL Server with login and password (so that other developers can work on the site locally, maybe I'm wrong and Windows authentication also be approached). Using Management Studio, I added a login for the server and user for the database, has appointed it the right db_owner, allowed ticks all the action at all to the server. Checked - in Management Studio with this username password connection is made, you can go to the table, everything works. I changed the connection string on the site.

<add name="GnrlBase" 
     connectionString="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\articlesbase2.mdf;User Id=mylogin;Password=mypassword;MultipleActiveResultSets=True;App=EntityFramework" 
     providerName="System.Data.SqlClient" />    

When trying to connect to the database fails with the following error:

Login failed for user ' the user who successfully connected to the management studio '

Why???

Sorry for the first wrong answer.

I think this website should help to understand how your connectionstring works.

@Zippy was right.

Standard Security

Server=myServerAddress;Database=myDataBase;User Id=myUsername; Password=myPassword;

SQL Server 2000

SQL Server 2005

SQL Server 2008

SQL Server 2012

SQL Server 7.0

Trusted Connection

Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;

SQL Server 2000

SQL Server 2005

SQL Server 2008

SQL Server 2012

SQL Server 7.0

Connection to a SQL Server instance

The server/instance name syntax used in the server option is the same for all SQL Server connection strings.
Server=myServerName\\myInstanceName;Database=myDataBase;User Id=myUsername; Password=myPassword;

SQL Server 2000

SQL Server 2005

SQL Server 2008

SQL Server 2012

SQL Server 7.0

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