简体   繁体   English

如何在Visual Studio中更改数据库?

[英]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. 我正在尝试在实际在服务器上运行的localhost中运行Web应用程序(以进行一些更改和测试)。 This application is coded in C# and the database is SQL Server Express. 该应用程序使用C#编码,数据库为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. 我制作了数据库副本,并将其加载到SQL Server 2012中。但是,当我运行应用程序时,在登录屏幕中,与数据库的连接失败。 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: 我使用来自SQL Server 2012本地数据库的信息在Visual Studio上创建了数据库连接,而我的web.config连接字符串如下所示:

<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 System.Data.Entity.dll中发生类型为'System.Data.EntityException'的异常,但未在用户代码中处理

Additional information: The underlying provider failed on Open. 附加信息:基础提供程序在打开时失败。

You are still pointing to your sql express database server. 您仍然指向您的sql express数据库服务器。 'data source=JJ-PC\\sqlexpress'. '数据源= JJ-PC \\ sqlexpress'。

Try to point to SQL Server 2012 with SQL server authentication like below: 尝试使用SQL Server身份验证指向SQL Server 2012,如下所示:

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. 如果您使用一种方法(Windows安全性)通过VS连接到数据库,而使用另一种方法(SQL Server身份验证)从网站进行连接,则可能发生这种情况,反之亦然。 At least, I think that can make that happen 至少,我认为这可以实现

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM