I have a MVC5 project with individual authentication.
Now I want to move from (localdb)\MSSQLLocalDB to another SQL Server database.
I've tried to change connection string from this :
Data Source=(localdb)\MSSQLLocalDB;Integrated Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
to this:
Data Source=PC-GABRI;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
And the application is still using localDB instead of my new SQL Server DB.
I have already migrated the database and roles.
I have also tried to comment all of my connection string form Web.Config but my application is still working and I can login with my "test" user.
I can't find anything on the web about this!
PS.
Related Questions: Switch LocalDB to SQL server db with MVC5
We have the same problem!
UPDATE 1
DB Instance:
Connection String:
The instances are running correctly.
Tell me if you need more info.
UPDATE
This Guide was very useful for me :
https://danieleagle.com/2014/05/setting-up-asp-net-identity-framework-2-0-with-database-first-vs2013-update-2-spa-template/
Follow all the easy steps for move your LocalDB table to SQL server db Table.
1. Inspect the Web.config File Connection String and Connect to Local Database
Change the defaut connection string:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApp-20190226025646.mdf;Initial Catalog=aspnet-WebApp-20190226025646;Integrated Security=True" providerName="System.Data.SqlClient" />
To your connection string:
<add name="DefaultConnection" connectionString="Data Source=PC-YWGSB;Initial Catalog=WebApp;user id=admin;password=admin" providerName="System.Data.SqlClient" />
2. Then use the commands for DB Migration "Codefirst"
This is the official guide:
https://learn.microsoft.com/it-it/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application
From the Tools menu, select NuGet Package Manager > Package Manager Console.
At the PM> prompt enter the following commands:
enable-migrations
add-migration InitialCreate
update-database
The database will be created automatically during migration.
If you already have one make sure to backup all tables.
Related
I have created a SQL Server database on Amazons Web Services. This means that I'm not authorized to edit the master database (or I believe so).
I followed the tutorial code-first migrations with an existing database
And I have been able to use the commands
Enable-Migrations
Add-Migration InitialCreate –IgnoreChanges
But when I use this command
Update-Databse
I get this error
This operation requires a connection to the 'master' database. Unable to create a connection to the 'master' database because the original database connection has been opened and credentials have been removed from the connection string. Supply an unopened connection.
And my connection string looks like this
<connectionStrings>
<add name="DBContext"
connectionString="data source=DBName.ctekr2i3aabo.eu-central-1.rds.amazonaws.com,1433;initial catalog=WeeklyReview;persist security info=True;user id=theodor349;MultipleActiveResultSets=True;App=EntityFramework"
providerName="System.Data.SqlClient" />
</connectionStrings>
I needed to supply the password for the connection.
I am doing Microsoft's MVC getting started tutorial:
Getting Started with Entity Framework 6 Code First using MVC 5.
This includes the creation of a code first database.
It all works fine, but I am not able to find my database.
This is my ConnectionString:
<add name="MovieDBContext" connectionString="Data Source=.\SQLEXPRESS; Integrated Security=True" providerName="System.Data.SqlClient"/>
If I debug my index Method the connection is as follow:
Data Source=.\SQLEXPRESS; Integrated Security=True
But there is no Database in my SQLEXPRESS Instance, I have checked it with SQL Server Management Studio.
I also cant find anything if I search my filesystem for *.mdf.
App_Data in my Project is Empty...
But all CRUD operations are working fine, there has to be something.
The only way I can see that table is to connect to .\SQLEXPRESS via the Visual Studio Server Explorer. But where is this physically located? Why cant I see the table if I connect to .\SQLEXPRESS via SQL Server Management Studio?
Any idea?
You didn't specify the Initial Catalog in your connection string so probably you are using the Master database.
You need to specify the Initial catalog like this:
<add name="MovieDBContext"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=yourDBName;Integrated Security=True"
providerName="System.Data.SqlClient"/>
I've created a new web app project template in VS community 2015, when I debug the project, it create its own default SQL Server database in MSSQLLocalDB with a default database name like aspnet-WebDBTest-20151026010545.
I've tried to change the debug database to a SQL Server Express database.
have changed web.debug.config file with new connection string on SQLEXPRESS
<connectionStrings>
<add name="ApplicationServices"
connectionString="Data Source=.\sqlexpress;Initial Catalog=TEST;Integrated Security=True"
providerName="System.Data.SqlClient"
xdt:Transform="SetAttributes" xdt:Locator="Match(name)" />
</connectionStrings>
I went to project properties and changed configuration (Active-debug -Any Cpu) changed Database Entry detail, set destination SQL Server database and destination connection string and verified.
I even went to Tools > Options > Database Tools > Data Connections
and set SQL Server Express instance name
But still when I run project in debug mode and add some user data, project is running its default database on MSSQLLocalDB
Any ideas? Am I running correct setting? (Please note I've created my destination database on SQLEXPRESS)
I am trying to follow the pluralsight course ASP.NET MVC 4 Fundamentals. But can't have my database connected.
Here is the error I got:
An error occurred while getting provider information from the database. This can be caused by Entity Framework using an incorrect connection string. Check the inner exceptions for details and ensure that the connection string is correct.
I have visual studio 2013 professional and SQL server 2012 installed on my machine. When I installed my SQL server, I created a server name "ABC" on my computer.
I have also installed sql localdb 11.0 separately, but it seems VS can't find the localDb connection. When I check Server Explorer -> add Connection, under server name list, only "ABC" is shown up.
Here is the connection string.
I also tried to use "Data Source = ABC; ...." it doesn't work either.
Update
Here is my connection string
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-eManager.Web-20141223223418;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-eManager.Web-20141223223418.mdf" providerName="System.Data.SqlClient" />
You could try this
In server explorer, right click, Choose Add Connection
enter (localdb)\v11.0 in as the server name
Choose your database and press connect
Right click properties on your new connection
Use that connection in string in your default connection
I.e.
<add name="DefaultConnection" connectionString="<Paste-connection-string-here>" providerName="System.Data.SqlClient" />
If that doesn't work, lets try starting it from the command line
Open command prompt
Run SqlLocalDB.exe start v11.0
Follow original steps , use the named pipe as your server name
If that doesn't work, lets try and connect via named pipes
Open command prompt
Run SqlLocalDB.exe info v11.0
Copy the Instance pipe name that starts with np:...
Follow original steps , use the named pipe as your server name
e.g
Run this command to make sure what is the version of your LocalDB
sqllocaldb info
So in my case the version is MSSQLLocalDB then the connection string will look like this
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=IdentityManagerDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
To add on to TheGeneral use view - SQL Server Object Viewer and look immediately under the "SQL Server" object. You'll see the name of the connect looking something like "(localDB)\ProjectsV13" Hand enter that into the connection box then you can browse the server for the database you want to use.
I've Create MVC5 APP with Local DB like the following link(step 1 to 5)
http://www.asp.net/mvc/tutorials/mvc-5/database-first-development/creating-the-web-application
And the application is running as expected and now I need to change the DB from the
sql Lite to azure DB ,I have created the same DB in azure (same data structure)and now what I want that the application use this DB ,There is simple way to do that ?
Im using VS2013 for web.
Just change the "source" and "initial catalog" parameters of the connection string in the web.config file.
Also, SQL Azure doesn't work with integrated security so you need to remove the "integrated security" parameter from the connection string and add the parameters "User ID" and "Password" with the credential of a user that you created in SQL Azure.
Open Visual Studio In Solution Explorer
find the file web.config
Look for the section connectionStrings
You should find something similar to:
<add name="testEntities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=System.Data.SqlClient;provider connection string="data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\test.mdf;integrated security=True;connect timeout=30;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
You need to:
Replace (LocalDB)\v11.0 with the name of your server
Remove "attachdbfilename=|DataDirectory|\test.mdf;integrated security=True;"
Add "Initial catalog=[name of your database in SQL Azure];user id=[name of your user id on SQL Azure];password=[your password]