5

I am programming a Weatherstation which gets the data from an API. This works fine, but I want to store it in a database to draw a graph with it. But my code does not seem to work. I tried debugging it and it fails on the line where I want to open the database. It runs through the line where I create the DB.

These are the failing lines:

databaseCon = new SqlConnection(@"Data Source=
(LocalDB)\v10.0;AttachDbFilename=C:\Users\Jeroen
Laptop\Desktop\Eindopdrachten\WeatherStation\Eindopdracht\
Weather.mdf;Integrated Security=True;");
databaseCon.Open();
        

Error message in the console:

A first chance exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

What happens:

I want to get the data from the API and put this into the DB for making a graph with temperatures, location and date. For this I created a database and I want to connect with it. This is where the error kicks in. I get the error from above. When I debug that message shows up a few times(100 or so) and continues to run, without filling the database.

I hope someone here can give me some more information or can see what I do wrong.

Update:

I got the following message when trying to acces the database

An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in System.Data.dll

Additional information: 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.)

I use Visual Studio 2010 with SQL server 2008. 2012 is not supported by my programming laptop.

7
  • 1
    You could start giving us some information about the error message. Commented Oct 3, 2013 at 14:54
  • Define "fails." What indication do you have that it's not working as intended? Is there an error message? Commented Oct 3, 2013 at 14:54
  • 1
    Shouldn't that be Data Source=(localdb)\v11.0;..... (v11.0 instead of v10.0) Commented Oct 3, 2013 at 14:55
  • Im using Visual Studio 2010. Some information will be here soon Steve! Commented Oct 3, 2013 at 14:57
  • 1
    Obvious question but Is SQL Server Express running ? Commented Oct 3, 2013 at 16:11

3 Answers 3

1

It must be v11.0, not v10.0, and in the future there will be v12.0+, but there is no v10.0. This has nothing to do with Visual Studio 2010 or SQL Server 2008. LocalDb first came with SQL Express 2012 and is v11.0. http://blogs.msdn.com/b/sqlexpress/archive/2011/07/12/introducing-localdb-a-better-sql-express.aspx

LocalDb also required as least .NET 4.02, but unfortunately the version in the registry is always v4.0.30319, even if you have earlier .NET http://blogs.msdn.com/b/sqlexpress/archive/2011/10/27/net-framework-4-now-supports-localdb.aspx

If possible, just upgrade to .NET 4.5

This problem can also exist if using a named instance instead of v11.0 and the program or service was ran as a different user and that user instance is still attached to the database. Unfortunately the database can take awhile to automatically detach.

Sign up to request clarification or add additional context in comments.

Comments

0

My guess is that it is probably a permissions error of some sort.

You are creating the DB on your desktop and I would bet that SQL server doesn't have rights to that folder.

Comments

0

Connection to a LocalDB requires this connection string

Automatic Instance

 Server=(localdb)\v11.0;Integrated Security=true;
                  ^^^^^

With a specific data file

 Server=(localdb)\v11.0;Integrated Security=true; AttachDbFileName=.......;

See the references on connectionstrings

Also, the version of the NET Framework required to connect is 4.02, you could check on

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\v4.0.30319\SKUs\

5 Comments

I checked all this, but the problem is still there. Is my whole code usefull maybe?
Do you have something in the InnerException field of the main exception, sometime the real problem is indicated there. I suppose that you have installed the SQL Server bits, right? kodyaz.com/sql-server-2012/sql-server-2012-localdb-setup.aspx
I will look at this in a bit. Actually, I remember that I had problems with an other database, maybe I deleted some wrong files. I will look for this also!
Hmm did not found sql server. Installing it right now. I wonder if the problems are solved when it's up!
Hmm, Some problems with SQL 2012. I will edit this post later on!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.