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.
Related
I need help solving this problem. I created the application installer using MS Visual Studio Installer Projects and ran it on another device. There were no versions of LocalDB that installed on my computer (2016 and 2017) in the prerequisites, so I had to download the SQL Server 2017 LocalDB on another computer manually. After that, when I started the program I received the following error.
Database files were automatically placed during installation in the folder Documents
I changed the connection string as follows:
string dbPathMyDoc = Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments);
string dbPath = Path.Combine(dbPathMyDoc, "myprojectAppData");
AppDomain.CurrentDomain.SetData("DataDirectory", dbPath);
Database path
So it seems to me that the problem is not the connection string, but then what?
I found that I can not check the version of SQL Server LocalDB installed on a second computer through the Command Prompt using the command sqllocaldb info MSSQLLocalDB (because of an error).
So I decided to recreate the MSSQLLocalDB instance using the following commands:
1) sqllocaldb d MSSQLLocalDB
2) sqllocaldb c MSSQLLocalDB
And after that the program successfully connected to the database.
I hope this information helps someone.
I make sample fixed problem for all project when create ny winforms & localdb
You can create 2 ConnectionString in App.config file
App.config
<add name="DevConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\MyDatabase.mdf;Integrated Security=True"
providerName="System.Data.SqlClient" /> <!-- *1* Use when publish project-->
<!--<add name="AppConnectionString"
connectionString="Data Source=(LocalDB)\MSSQLLocalDB;AttachDbFilename='E:\My Projects\MyDatabase.mdf';Integrated Security=True"
providerName="System.Data.SqlClient" />-->
<!--*2* Use for development-->
First use when you want develop system Developer Environment
Second CS use when app publish Publish Environment
For second connection-string must write full path
Code
For get connection String in App.config file, you can use this code
var conStr = ConfigurationManager.ConnectionStrings["DevConnectionString"].ConnectionString;
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.
I've seen this error answered for other people, but I can't seem to get it to work. I'm trying to connect to a SQL Server Database project locally.
I'm getting this error thrown on Open() when I do the follow:
SqlConnection conn = null;
conn = new SqlConnection(connection)
conn.Open()
Where connection is a connection string passed from my webconfig. I've found examples online and tried these three connection strings and I get the same error every time:
<add name="TICKETING_CONNECTION" connectionString="Server=(local); DataBase=Ticketing_DB; Integrated Security=SSPI"/>
<add name="CONN"
connectionString="Data Source=localhost; Integrated Security=SSPI;Initial Catalog=Ticketing_DB"
providerName="System.Data.SqlClient" />
<add name="CONN2"
connectionString="Data Source=(local);Initial Catalog=Ticketing_DB;"
providerName="System.Data.SqlClient"
/>
Could the problem be stemming from the path of where the database is located on my machine? I've tried copying the c:\ path but didn't have any luck. I've seen some examples online use a .mdf file, but my project does not have this file either.
This is my first time trying to connect to a database project, so any help or advice would be greatly appreciated
If you are using Visual Studio try going to the Server Explorer and Right click on Data Connections and Add new connection by selecting DataSource as Microsoft SQL Server and provider as .net framework provider for SQL Server.
Under the server name check for the SQL Server if it is listed with your machine name.
Then try to provide the database details and user name and password for SQL Authentication or select windows for windows authentication. Then do a test connection. If it is fine on click of OK it will add the data connection.
Right click the properties of data connection which is newly added and navigate to properties to extract the connection string. Compare it with yours. This can help you troubleshoot the issue.
I'm having a problem switching a project I am working on over to another system. It's an ASP.Net web application and web form wrapped in a single solution, with a SQL .mdf DB file in the project as well. I'd like to be able to zip up the whole thing and move it around, but when trying to debug the solution on the other machine I get an error about the local DB not existing. My connection string in the Web.Config file looks like this:
<connectionStrings>
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-name-of-database.mdf;Initial Catalog=aspnet-name-of-database;Integrated Security=True"
providerName="System.Data.SqlClient" />
</connectionStrings>
I know I must be making an obvious mistake, but I can't figure out what it is. Any advice, please? Thanks.
Edit: The specific error is:
"The specified LocalDB instance does not exist."
Run the following from your package manager console:
SqlLocalDb info
If the executable isn’t found, chances are you do not have LocalDb installed in your new machine. You can use the steps mentioned in the below link to debug as to why the connection is not successful to your localDB:
http://odetocode.com/blogs/scott/archive/2012/08/15/a-troubleshooting-guide-for-entity-framework-connections-amp-migrations.aspx
Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database.mdf;Integrated Security=True;User Instance=True
Try setting the Datasource as below.
Data Source=.\;
If you are able to connect to your database, then the set the ServerName as DataSource in your connection string.
Make sure you have SSMS installed in your new system.
Download SQL Server Express 2014
I have created a WPF application which used entity framework and SQL server 2012 for database. It runs fine on my machine. But when I ran this on client machine I received exception. This happens when I am trying to add a record in database.
Exception: The underlying provider failed on Open
Inner Exception: 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, ........
Connection string:
<connectionStrings><add name="SchoolModelContext"
connectionString="metadata=res://*/SchoolModel.csdl|res://*/SchoolModel.ssdl|res://*/SchoolModel.msl;
provider=System.Data.SqlClient;provider connection string='data source=(LocalDB)\v11.0;
initial catalog="SCHOOLDB.MDF"
integrated security=True;MultipleActiveResultSets=True;
App=EntityFramework'" providerName="System.Data.EntityClient" />
</connectionStrings>
The error message ... it gives hints that are sometimes rabbit-trails. Basically the error is saying "I can't connect to sql Server, there is something wrong".
But.. you say you "installed SqlLocalDB" on the client.
Did you "wire up" the new database (SCHOOLDB)?
http://msdn.microsoft.com/en-us/library/hh212961.aspx
A. Creating an Instance of LocalDB
The following example creates an instance of SQL Server Express LocalDB named SCHOOLDB using the SQL Server 2012 binaries and starts the instance.
SqlLocalDB.exe create "SCHOOLDB" 11.0 -s
Aka, did you run something like that?
(Other info from the MSDN article that may not be relevant to this question)
B. Working with a Shared Instance of LocalDB
Open a command prompt using Administrator privileges.
SqlLocalDB.exe create "SCHOOLDB"
SqlLocalDB.exe share "SCHOOLDB" "SchoolSharedLocalDB"
SqlLocalDB.exe start "SCHOOLDB"
SqlLocalDB.exe info "SCHOOLDB"
REM The previous statement outputs the Instance pipe name for the next step
sqlcmd –S np:\\.\pipe\SCHOOLDB#<use your pipe name>\tsql\query
CREATE LOGIN NewLogin WITH PASSWORD = 'Passw0rd!!#52';
GO
CREATE USER NewLogin;
GO
EXIT
Execute the following code to connect to the shared instance of LocalDB using the NewLogin login.
sqlcmd –S (localdb)\.\SchoolSharedLocalDB -U NewLogin -P Passw0rd!!#52
EDIT ::: (only read above this line for a general understanding...see below on steps I actually did)
Ok, the above is a little confusing because its hard to know if you're dealing with the ~instance or the database.
Let's try this:
SqlLocalDB.exe create "MySuperCoolLocalExpressInstance"
SqlLocalDB.exe share "MySuperCoolLocalExpressInstance" "MySuperCoolLocalExpressInstanceSHARED"
SqlLocalDB.exe start "MySuperCoolLocalExpressInstance"
SqlLocalDB.exe info "MySuperCoolLocalExpressInstance"
NOW, very important, get YOUR very unique "named pipe" value.
np:\\.\pipe\LocalDB#<use your pipe name>\tsql\query
Copy your SchoolDB.mdf and SchoolDB.ldf to :
c:\MyCoolLocalDatabaseFiles\
Now set your connection string to this:
<connectionStrings>
<add name="SchoolModelContext"
connectionString="metadata=res://*/SchoolModel.csdl|res://*/SchoolModel.ssdl|res://*/SchoolModel.msl;
provider=System.Data.SqlClient;provider connection string="data source=np:\\.\pipe\LOCALDB#MYUNIQUEPIPENAME\tsql\query;attachdbfilename=C:\MyCoolLocalDatabaseFiles\SchoolDB.mdf;integrated security=True;multipleactiveresultsets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
But substitute "MYUNIQUEPIPENAME" for your value.
The key is "attachdbfilename". This is how to "on the fly" attach a database.
You have some alternates for using the named pipe syntax. See:
http://www.connectionstrings.com/sql-server-2012
"User Instance on local SQL Server Express"
enter code here