简体   繁体   中英

how to change the database in visual studio?

I am trying to run a web application in localhost (to do some changes and tests) that actually is running on a server. This application is coded in C# and the database is SQL Server Express. I made a database copy and I loaded it on my SQL Server 2012. But when I run the application, in the login screen, the connection to the database fails. I created the database connection on the Visual Studio with the info from my local database of SQL Server 2012, and my web.config connection string is like this:

<connectionStrings>
    <add name="movieDb" 
         connectionString="metadata=res://*/Model.csdl|res://*/Model.ssdl|res://*/Model.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=JJ-PC\sqlexpress;initial catalog=movie;multipleactiveresultsets=True;App=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />
    <add name="movieDbDocs" 
         connectionString="metadata=res://*/ModelDocumentos.csdl|res://*/ModelDocumentos.ssdl|res://*/ModelDocumentos.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=JJ-PC\sqlexpress;initial catalog=movieDocs;multipleactiveresultsets=True;App=EntityFramework&quot;" 
         providerName="System.Data.EntityClient" />
</connectionStrings

And the error is in the following line while debugging:

var result = db.Usuarios.FirstOrDefault(p => p.USERID == login);

and says:

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

Additional information: The underlying provider failed on Open.

You are still pointing to your sql express database server. 'data source=JJ-PC\\sqlexpress'.

Try to point to SQL Server 2012 with SQL server authentication like below:

It can happen if you're connected to the database with VS using one method (windows security) and connect from the website using another method (SQL Server Authentication), or vice versa. At least, I think that can make that happen

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