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'm trying to get my local SQL database connecting to my ASP.Net project and nothing I try is working.
The database is named cinemaDatabase and its using windows authentication.
In web.config I have
<connectionStrings>
<add name="myDatabase" connectionString="Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=cinemaDatabase;Integrated Security=True;" providerName="System.Data.SqlClient" />
</connectionStrings>
Then in a cshtml page I have
#using WebMatrix.Data;
#{
var db = Database.Open("myDatabase");
}
I keep getting this error
InvalidOperationException: Connection string "myDatabase" was not
found. OpenNamedConnection
What am I doing wrong here? Thanks in advance.
Edit -
Got it working, had to make a normal SQL server instead of the local MSSQLLocalDB one and change the data source in web.config to that.
Then used this code on my page and it connects now.
#using WebMatrix.Data;
#using System.Data.SqlClient;
#{
var connectionString = "Data Source=DESKTOP-58NGNQP;Initial Catalog=webDev;Integrated Security=True";
var providerName = "System.Data.SqlClient";
var db = Database.OpenConnectionString(connectionString, providerName);
}
I believe the problem is with your connection string. Unfortunately, I don't have a running example right this moment with an attached .mdf file, but I believe something like this will do the job for you, I grabbed this string from MSDN's article on connection strings
<add name="ConnectionStringName"
providerName="System.Data.SqlClient"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFileName=|DataDirectory|\DatabaseFileName.mdf;InitialCatalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True" />
Couple of important facts here:
Data Source=(LocalDB)\v11.0 - This specifies the start-on-demand localdb instance to use. Note that the version, v11.0 in this string, varies from installation to installation, and you should find the correct version for your string. (You should be able to find it easier below)
AttachDbFilename=|DataDirectory|\DatabaseFilename.mdf - this tells LocalDb to load that database file. Alternatively, localdb persists database files in your user home directory, or AppData directory somewhere.
Integrated Security=true - A connection string needs an authentication scheme. Two possible options are Integrated Security, which uses your windows credentials to attempt access to your database, which works well with many things, LocalDb being one of them. Another option is to use sql authentication and a sql name and password to connect.
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 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.
Background-info:
I'm using Microsoft Visual Web Developer 2010 Express.
Info about my (lack of) experience: the problem occured within the first tutorial that I'm trying to work through.
Some additional-info:
I'm comfortable with C#, Postgres, Rails (so MVC & Web-apps are not new to me)
I have no experience with ASP.NET or SQL Server
Problem Description:
I'm trying to following exactly the steps from the "Intro to ASP.NET MVC 3"-tutorial and I'm running into a problem at the first step from part 5 - Adding the MoviesController:
When I'm trying to add the "MoviesController" with the exact settings that are shown in the tutorial and click 'Add' I get the following error:
"Unable to retrieve metadata for
MvcMovie.Models.Movie. Unable to
find the requested .Net Framework Data
Provider. It may not be installed."
Google gave a ton of results when searching for the phrase "Unable to find the requested .Net Framework Data Provider", but nothing has solved the problem so far.
What I've tried:
I think SQL-Server was not installed so I installed it from the Visual-Studio Express ISO- got an error then I've run a repair from the ISO and it claimed that all 15 points including SQL Server Express repair &.NET 4 Framework went through successfully.
I've run the The_.NET_Framework_Setup_Verification_Tool which succeeded for everything.
http://blogs.msdn.com/b/astebner/archive/2008/10/13/8999004.aspx
After the mentioned (re-)installing & repairing I recreated the Project and followed every step as described in the tutorial and got the same error.
I found that I should look for DbProviderFactories in machine.config,
The root-Web.config of the Project has the following entries
<connectionStrings>
<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
My machine config-file has only one DbProviderFactories entry:
<DbProviderFactories>
<add name="Microsoft SQL Server Compact Data Provider" invariant="System.Data.SqlServerCe.3.5" description=".NET Framework Data Provider for Microsoft SQL Server Compact" type="System.Data.SqlServerCe.SqlCeProviderFactory, System.Data.SqlServerCe, Version=3.5.0.0, Culture=neutral, PublicKeyToken=89845dcd8080cc91"/></DbProviderFactories>
then I found the following quote
"we have changed the way
DbProviderFactories.GetFactoryClasses()
determines the framework providers in
VS2010. They are no longer listed in
the machine.config file. "
from http://social.msdn.microsoft.com/Forums/en-ZA/adodotnetdataproviders/thread/d79129c4-ae05-4c45-8997-bd90f5765a3a
Question:
So perhaps this is the wrong direction and since I have no clue what to try next, what steps should I take to investigate & solve this problem?
Btw. I have postgres installed, so if using postgres instead of SQL-server would be an easy solution let me know. For my own projects I would want to use a different DB anyway (probably postgres), but for now I would just want to be able to get successfully through the first and seemingly simple tutorial I've tried.
I was having the same problem so I replaced
<add name="MovieDBContext" connectionString="Data Source=|DataDirectory|Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
with the following
<add name="MovieDBContext"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;database=Movies;User ID=sa;password="
providerName="System.Data.SqlClient"/>
And it worked enough to let me continue working. I too would also eventually learn how to make these kinds of applications work with mysql at some point, but for now this should at least help you continue with the tutorial.
You need to install Microsoft SQL Server Compact 4.0.
If you look at the config you'll see that installing SQL Server was a red herring;
<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|Movies.sdf"
providerName="System.Data.SqlServerCe.4.0"/>
SqlServerCE is not, I'm afraid, full blown SQL Server, it's SQL Server Compact Edition. I would have thought that would have been installed with VS Express, however you can download the specific installers from here
I actually had both SQLServerCE and Express installed, but the tutorial used Compact Edition:
One step within part 4 of the tutorial is to explicitly add the part you quoted to the Web.config. So this is a part of the web.config by intention.
But deleting this part from the web.config makes it possible to add the Controller in the way the tutorial described it. While this means no longer exactly following the tutorial, it's fine for me. (This results in the creation of an MvcMovie.Models.MovieDBContext database in SQL Server Express.)
http://forums.asp.net/t/1679349.aspx/1
CypressBender
Re: Unable to retrieve metadata for * Unable to find the requested .Net Framework Data Provider....
Aug 08, 2011 07:44 PM|LINK
I installed Microsoft SQL Server Compact 4.0, and that fixed the problem for me.
http://www.microsoft.com/download/en/details.aspx?id=17876
I changed my SQL providerName="System.Data.SqlClient" in web.config , since I have SQL client as well as SQL compact installed on my system.
Rebuilding the project wont catch config errors in the DBContext section... the build process does not walk through connections, so you can build all day and still bomb out. As suggested above, fix the config so the connection string matches MachineName/SQLInstanceName/DBName with the correct SQL config. Worked just fine by just modifying my web.config in my solution.
Make sure that you build prior to adding the controller. If that doesn't work...
Create a new project, create a new sql server database manually and see if you can connect to it. If not, then the problem is indeed in your sql server config on your machine. You can try going to postgres just be sure that the provider you choose has support for EF code first.
What I did was in order to overcome the first problem I put in Web.config the code:
<add name="MovieDBContext"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Movies.sdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
Notice I am creating SQL CE 4 database, therefore the .sdf and not .mdf
Next, you should receive another connection errors on the page /Movies, so replace the above code with :
<add name="MovieDBContext"
connectionString="Data Source=|DataDirectory|\Movies.sdf;"
providerName="System.Data.SqlServerCe.4.0" />
And you should be fine.
I had a server. It ran windows updates. And a message waiting for restart was open.
After restart it worked again.
Install Microsoft SQL Server Compact 4.0. The link for same is - http://www.microsoft.com/en-us/download/details.aspx?id=17876
This worked for me, hope it helps
<add name="MovieDBContext"
connectionString="Data Source=(local);Initial Catalog=Movies; Integrated Security=true;" providerName="System.Data.SqlClient" />
</connectionStrings>
After reading other discussions around the web I have found another method.
If you do not add the connection string until after you have created the controller class, then it will work also. It kind of seems like a bug.
Try this:
<add name="MovieDBContext"
connectionString="data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|Movies.sdf;User Instance=true"
providerName="System.Data.SqlClient" />