My development machine has multiple versions of LocalDb. After running an initial EF migration the database was created in (localdb)\MSSQLLocalDB (SQL Server 12.0.4213...). I expected it to land in (localdb)\v11.0 (SQL Server 11.0.3000...).
The connection string in app.config is
<add name="HomeCinemaDan"
connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=HomeCinemaDan;Integrated Security=SSPI; MultipleActiveResultSets=true"
providerName="System.Data.SqlClient" />
What configuration line does EF migrations read to determine which db version to install to?
Background: I'm following this tutorial and I've reached the end of the Data Repositories segment (I'm at the line that reads update-database -verbose). I've changed the database name to HomeCinemaDan.
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 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.
I developed an asp.net website (using webforms) and for database connection I used Entity Framework. On my local computer everything is working fine. Now I try to host it I am having a problem. I have copied my files to the production server and attached my SQL Server database and set my connection string to:
<add name="ConnectionString"
connectionString="Data Source=SQL5003.Smarterasp.net;Initial Catalog=DB_9C4561_WFormBlog;User Id=DB_9C4561_WFormBlog_admin;Password=mydbpwd"
providerName="System.Data.EntityClient" />
but when I test my website am getting error:
Keyword not supported: 'data source'
When I removed "data source", it started complaining of "Initial catalog" keyword not supported.
Please help me out. You can refer me step by step tutorial or material that can put me through. Thanks in advance!
Try the below format, I have my database on smarterasp.net and it works well
<connectionStrings>
<clear />
<add name="ConnectionString" connectionString="Persist Security Info=False;database=DB_9C4561_WFormBlog;server=SQL5003.Smarterasp.net;user id=DB_9C4561_WFormBlog_admin;password=mydbpwd;Current Language=English;Connection Timeout=60;" />
</connectionStrings>
I am trying to use code-first approach of Entity Framework in my asp.net mvc application. Below is my connection string which was autogenerated...
<connectionStrings>
<add name="ApplicationServices" connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true" providerName="System.Data.SqlClient" />
</connectionStrings>
Whenever I press F5, the following error occurs:
A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.)
What am I doing wrong??
I have SQL Server 2008 Enterprise edition installed. I am trying to connect to SQL Server using Windows authentication. I am also following a video tutorial so there may not be anything wrong with code
IF you have SQL Server Enterprise edition, you most likely won't have it installed as SQLEXPRESS instance (that's the default for the SQL Server Express installations that come with Visual Studio).
More likely than not, you have the unnamed default instance - so try to use this connection string:
<connectionStrings>
<add name="ApplicationServices"
connectionString="data source=.;Database=YourDatabaseName;Integrated Security=SSPI;
providerName="System.Data.SqlClient" />
</connectionStrings>
Not sure if your application really uses the ApplicationServices connection string - if not, adapt the one your app is using! Also, you'll need to replace the YourDatabaseName with the actual database name that you're using in your application.
If you are trying to connect to an instance of SQL server that's installed on your machine, you'll want to use a connectionString formatted to use that instead. Your current connectionString is trying to create a database file from which to work, rather than building a database in your SQL server instance.
Try something like this;
connectionString="data source=localhost;user id=<user with dbo access>;password=<user password" providerName="System.Data.SqlClient" />
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