I was following the tutorial on creating the Code First Entity Framework model on Asp.NET MVC Application from this tutorial.
As I proceeded, a file with the .mdf extension should have been generated under the App_Data folder in my project (in the solution explorer section). Currently this folder is empty.
I have tried building the project and cleaning it. Moreover I have enabled Show All Files option in the folder. I even did a refresh. The Entity Framework works just fine and is able to connect and retrieve from the database. However the App_Data folder is empty.
Here is are my connection strings:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-UsingEntityFramework-20161002112829.mdf;Initial Catalog=aspnet-UsingEntityFramework-20161002112829;Integrated Security=True"
providerName="System.Data.SqlClient" />
<add name="MovieDBContext" connectionString="Data Source=tcp:xxxxxxxxxx.net;Initial Catalog=xxxxx;User ID=xxxxx;Password=xxxxxx;" providerName="System.Data.SqlClient"/>
</connectionStrings>
Check your web.config and notice the connectionString and see the data source, maybe it is creating it under your SQL Server not inside the App_Data
The MDF File will be created when the database is created, and since this is a code first, the database will not be created unless you run the application and start connecting to the database, EF will create the database if it doesn't exist and will compare the schema to the schema in the Migrations folder and it will update the database if it is not up to date.
You can also open Nu Get Package Manager and run the command Update-Database to create and update the database.
Related
Im trying to deploy application application with localdb. What I currently achieved is that I created mdf file from my localdb and add it to setup project (Visual Studio Installer). I modified connection of mdf file to localdb database. What I'm worried about this solution, when I'll edit database and install updates on client PC, if the data from mdf file will be lost. Is there a better way how to deploy or is this method valid?
Problem with this method is that I cant reach my stored procedure, even server explorer shows them.
Using VS 2015, SQL Server 2016 and EF 6 in my app.
Connection string, first one was initial one, connecting right to localdb, second one is connecting to mdf file. First one si working correctly, but only on dev machine, second one is having problems.
<connectionStrings>
<add name="MSDBContext" connectionString="data source=(localdb)\MSSQLLocalDB;initial catalog=MSDatabase;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
<add name="MSDBContextFile" connectionString="data source=(LocalDB)\MSSQLLocalDB;attachdbfilename=|DataDirectory|\MSDB.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework" providerName="System.Data.SqlClient" />
</connectionStrings>
I'm new in ASP.NET Development
I create MVC Project and as I understood it creates with default .mdf database.
I working with it and all was great, but I think about deploying app to azure.
So I need to use azure database.
I create it , all ok.
I read article how connect to azure db.
As I understood , I need connection string
Here it is
Server=tcp:smartsolutionsserver.database.windows.net,1433;Initial Catalog=smartdatabase;Persist Security Info=False;User ID={your_username};Password={your_password};MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;
As I understood I need to paste it to Web.Release.config
I do this, so now it have look like this
<connectionStrings>
<add name="DefaultConnection"
connectionString="Server=tcp:smartsolutionsserver.database.windows.net,1433;Initial Catalog=smartdatabase;Persist Security Info=False;User ID=*********;Password=******;MultipleActiveResultSets=False;Encrypt=True;TrustServerCertificate=False;Connection Timeout=30;"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)"/>
</connectionStrings>
But as I understood .mdf database connections wrote in Web.config file
And looks like this
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-SmartSolutions-20170124034333.mdf;Initial Catalog=aspnet-SmartSolutions-20170124034333;Integrated Security=True" providerName="System.Data.SqlClient" />
Tell me, how I can connect to azure database and use it instead of local .mdf database?
Thank's so much for help.
UPDATE
I try to add 2 new tables and publish app. After connecting to database from SQL Server Object Explorer, I see that tables added.
But when I try to register new user I see this
On local all ok
Screen
So my error was in The model backing the 'ApplicationDbContext' context has changed since the database was created
I go to table __MigrationHistory and delete row. After that, all okay. All works
# juunas Thank's for advice. I do this and see error. Also it can visible if you use IIS Console
Ok after finally getting the correct connection string to create the Mdf file in the App_Data folder. I tried to add a ADO.NET Entity Data Model to the Models folder following the tutorial in "Beginnning ASP.NET MVC 4".
However once added I should have being able to expand the DataModel.edmx to show the model classes, all thats showing is the DataModel.Designer.cs .
Has anyone come across this before ?
Also should I also be seeing this database in my SQL Express ?
Visual studio 2010, windows xp machie
Original Connection string, in case it helps...
<add name="DefaultConnection" connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=HaveYouSeenMe;AttachDbFilename=|DataDirectory|HaveYouSeenMe.mdf;Integrated Security=True;User Instance=True" providerName="System.Data.SqlClient" />
Connection string added when created ADO.NET Entity Data Model.
<add name="EntitiesConnection" connectionString="metadata=res://*/Models.DataModel.csdl|res://*/Models.DataModel.ssdl|res://*/Models.DataModel.msl;provider=System.Data.SqlClient;provider connection string="data source=.\SQLEXPRESS;attachdbfilename=|DataDirectory|\HaveYouSeenMe.mdf;integrated security=True;user instance=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" /></connectionStrings>
open your EDMX and in Properties Window change Code generation strategy to Default and save your EDMX file
Update
Check out following link for more details
Database First Approach in Entity Framework
When trying to publish our website on Windows Server 2008 R2, we are seeing the following error. Error 4 The process cannot access the file 'C:\Users\Student\Desktop\CSFP Front-End\App_Data\ASPNETDB.MDF' because it is being used by another process.
We don't understand what else could be using the data file.
web.config looks like this
<connectionStrings>
<add name="FBConnectionString" connectionString="Data Source=SERVER4;Initial Catalog=AITP;Integrated Security=True" providerName="System.Data.SqlClient" />
<add name="ASPNETDBConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Users\Student\Desktop\CSFP Front-End\App_Data\ASPNETDB.MDF;Integrated Security=True;User Instance=True"/>
</connectionStrings>
<system.web>
It runs fine locally, and the roles and users work as well. "Build Web Site" also works just fine, but when we are trying to publish the website it throws the error. Any ideas?
while publish the project, first detach the database file. Then publish it will work fine. For detaching right click on App_Data->ASPNETDB.MDF, detach...
The simplest solution could be to simply close the .mdf file and restart Visual Studios. I've had to do this when felix's method doesn't work.
Another superstition I try is killing the "SQL Server" process with the Task Manager.
after creating asp.net page if we run that project it shows asp.net welcome
if we create a username and password and login the page.
after that if we want the users created their name and password where the data will be saved in project and how to check the login details.
if you are using default template which comes with Visual studio then the data will be stored into aspnetDb.mdf under the App_Data folder. you can check it with explorer. for this also you need to have SQL Excpress edition By default these template uses that ASpnetDb.MDF file for authentication data.
here is your sample Screenshot.
If you access your config file, you can find
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnetdb.mdf;User Instance=true"
providerName="System.Data.SqlClient" />
</connectionStrings>
Nota : AttachDBFilename=|DataDirectory|\aspnetdb.mdf is path of your DataBase.
You can open your DataBase in Server Explorer