1

Testing Entity Framework 6 with ASP.NET MVC and I got a problem: theoretically Entity Framework should create the database, after first query to it, if it does not exist.

In my case Entity Framework makes query, and SQL Server Express responds with

error 18456, state 38 : Cannot open database

My connection string is:

Data Source=.\SQLEXPRESS;Initial Catalog=BITSBotDB;User ID=***;Password=********;Integrated Security=SSPI

So question - what am I doing wrong?

marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
  • check the permission of the user in the sql, try to give the user `db_owner` role and try if the error stays or not – Monah Nov 30 '17 at 23:27
  • It is db_owner from very begining – Макс Бекетов Nov 30 '17 at 23:30
  • go to the SQL Server using SSMS and navigate to the Security > Logins > Right click on the account, and select properties. click on “User Mapping” tab and there check if the login is mapped to the database BITSBotDB and check then the database role , the error you have is related to the credentials of the login user – Monah Nov 30 '17 at 23:38
  • First of all, Entity framework should create database on server. Before my project on ASP.NET I've tried it in Windows Forms on my PC with LocalDB and it did create database. (Now I try it on remote server - win2016core + IIS10 + ASP.NET + SQLEXPRESS). Then I've allready tried to create database myself (with all the mappings you are telling) and it couse no resault. About credentials - I belive you're right, cause SQL log shows credentials as 'IIS APPPOOL\***', but description of state 38 tells, that credentials are fine. P.S. According to your login, can you speak russian, It would be easier) – Макс Бекетов Dec 01 '17 at 00:11
  • BTW I'm using 'Cde First' method – Макс Бекетов Dec 01 '17 at 00:20
  • Have you provided the `providerName` in the connection string? – Harsha KN Dec 01 '17 at 06:52
  • @МаксБекетов regarding your idea to conversate in russian: https://meta.stackexchange.com/questions/13676/do-posts-have-to-be-in-english-on-stack-exchange – grek40 Dec 01 '17 at 07:48
  • Yes, I've provided - `providerName="System.Data.SqlClient"`. Visual Studio added it for me. – Макс Бекетов Dec 01 '17 at 09:17
  • 1
    Remove `Integrated Security=SSPI` if you are using SQL credentials. If User ID and Password are specified and Integrated Security is set to true, the User ID and Password will be ignored and Integrated Security will be used. See [here](https://msdn.microsoft.com/en-us/library/system.data.sqlclient.sqlconnection.connectionstring(v=vs.110).aspx) – Steve Greene Dec 01 '17 at 15:19
  • @SteveGreene Yes, It work!!! Great thanks to you! I don't know how _Stackoverflow_ works, but if I have to do something to thank you, just tell me)) – Макс Бекетов Dec 01 '17 at 18:56
  • lol, no worries. Typos can cause the most annoying problems. – Steve Greene Dec 01 '17 at 20:14

0 Answers0