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>
Related
I am running Visual Studio in MAC OS. I have a web application developed in .NET. I want to attach this application with a database that I was able to configure and run using Docker in a localhost server.
If I were to work in Visual Basic (in windows) what I usually do to connect to the database is modify the "DefaultConnection" of the Web.config file:
<add name="DefaultConnection" connectionString="Data Source=mypc\SQLEXPRESS;Initial Catalog=MyDataBase;Integrated Security=True" providerName="System.Data.SqlClient" />
But in the case of MAC, as I am running the server in Docker, I don't know what should be the connection string. My question is how to find the string or what should I use as connectionString in this case where the database is in Docker.
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
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 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" />
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.