简体   繁体   中英

First chance exception of 'System.Data.EntityException'. The underlying provider failed on Open

I've been given a site that was created by someone else and I'm now trying to test it. I can compile the system without any problems but when I try to log in to the website, I get the error:

"EntityException occured. A first chance exception of type 'System.Data.EntityException' occured in System.Data.Entity.dll. Additional info: The underlying provider failed on Open."

Furthermore, if I dig deeper, I see an InnerException of Cannot open database \\"MyDB\\" requested by the login. The login failed. Login failed for user 'name\\\\owner'. Cannot open database \\"MyDB\\" requested by the login. The login failed. Login failed for user 'name\\\\owner'.

I've read similar problems on the web and it seems like its a problem with database connections? I've tried multiple 'solutions' that include messing around with the connectionString but nothing works.

What I think the system wants to do is connect to a .mdf located in a separate project's App_Data. Anyway, here's the connectionString code that I received originally:

add name="NameServiceContext"
connectionString="Server=tcp:qiu5vg5yhv.database.windows.net,1433;Database=MyDB;User ID=MYID;Password=MYPASS;Trusted_Connection=False;Encrypt=True;Connection Timeout=30;"
providerName="System.Data.SqlClient"

Quick question, what is the tcp:...... stuff? I'm assuming it was generated somehow, but how?

I've tried 'fixing' the problem and ended up with something like this:

add name="NameServiceContext" 
connectionString="data source=./SQLEXPRESS;AttachDbFilename=C:\Users\owner\Documents\MyERP\App_Data\MyDB.mdf;Integrated Security=True;Connect Timeout=30;" 
providerName="System.Data.SqlClient"

Both methods give the same errors and I'm out of ideas. How would I go about fixing this?

Also, when I connect to a db via tools>connect to database > MS SQL db file, I get an option between 2 data sources, ./SQLEXPRESS and (LocalDB)\\v11.0 . Do I have to include both of them? If so, how?

The original connection string refers to a Microsoft Azure instance. A typical connection string to Azure looks like:

Server=tcp:[serverName].database.windows.net;Database=myDataBase;User ID=[LoginForDb]@[serverName];Password=myPassword;Trusted_Connection=False;Encrypt=True;

Your server name is qiu5vg5yhv.database.windows.net . Most likely your credentials are incorrect.

It is as Andrew said, you don't seem to have access to the actual database. Simply download either "SQL Server Management Studio" or "SQL Server Management Studio Express" (depend on which version of database you are using) and try to connect.

If you connect successfully, check if you can query the database of your project. If you connect unsuccessfully, contact your system admin to arrange access.

If you want to understand more about connectionstring or create one, use the following site for template: http://www.connectionstrings.com/sql-server/

You can get the necessary database details by viewing the Properties of your database via "SQL Server Management Studio" (right click and select Properties --> View Connection Properties)

I met the same question. The key step is here. I used vs 2013 update 4. When you configured your SQL in azure, it generated a connect string.

在此处输入图片说明

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