Click here to Skip to main content
15,891,633 members
Please Sign up or sign in to vote.
4.00/5 (2 votes)
See more:
Hey everybody,

I am working on little Project for my tabletop Club, which needs a database to store the inventory of our shop. Therefore i wanted to use the Local Database that can be created in VS.

The Problem is, that i used VS2012 to create the Project, did all the stuff to get the .sdf database running. As i changed now to VS 2013 the .sdf DBFile doesn't exist anymore and as im not sure about the needed size for the DB i changed to the .mdf DB File.

I can't get a Connection now to this .mdf DatabaseFile with my Code, but can access it through the datasourcemanager / Serverexplorer.
So what im asking for is a clue if i need to use somithing similar to the sqlCe stuff or if ist working with the usual SQL classes. I'm really desperate now cause i searched tons of Forums about the "correct" Connection string and am still getting the same error that the Server is somehow down or not reachable.

So, how the he** do i use this Local Database? The CE stuff seemed quite easy!

Thanks in advance.

By the way, the Connection string: (As far as i remeber it)

C#
Data Source=(LocalDB)\v11.0;AttachDBFilename="Path\Database.mdf";Integrated Security=true; 
Posted
Updated 20-Aug-14 23:13pm
v3
Comments
Richard MacCutchan 21-Aug-14 3:44am    
I use a .sdf database with code developed in VS2013. What exactly is the problem you were having with it?
HobbyProggy 21-Aug-14 4:33am    
The Problem is i can't create, connect with the Server Explorer to my .sdf, thats why i dropped that. The connect string to the .mdf database seems not working, as i open a Connection with my code i always get ther error Code:40 database/ Server is unable to connect.

But it seems like i found a solution proposed by my collegue to create a Connection string via the Settings file in the Project, i'll give that a try and then give a reply if it worked.
Richard MacCutchan 21-Aug-14 4:40am    
Putting the connection string into the settings file is not going to solve your problem. You need to find out why the connection is failing, either your connection string is wrong, or SQL server is not running.
HobbyProggy 21-Aug-14 4:46am    
Yes i know that, i tried to find out and can't make it out where the Problem is.
But as i am using a local databasefile i thought i might not Need a Server running as the file is the "Server"? Or am i getting something wrong on that?

As i mentioned the Connection is only not working in my code, i have full Access with the Server Explorer in VS.
Richard MacCutchan 21-Aug-14 4:49am    
.mdf files (as far as I am aware) are used by SQL Server Express, so you do need a server instance running - that is what you connect to.

You may well be better using the compact edition which does not require a server.

You are missing the V!
C#
Data Source=(LocalDB)\v11.0;AttachDBFilename="Path\Database.mdf";Integrated Security=true; 
 
Share this answer
 
Comments
HobbyProggy 21-Aug-14 5:13am    
Ah :) that might be a typo, sorry for that :/
Herman<T>.Instance 21-Aug-14 5:52am    
How often have you used AttachDbFileName for that file? You can only use it once. After that the Database is registered in the LocalDB. Can you connect to the LocalDB via the SSMS (Management Studio)? If you see your DB there you can then use a regular connection string in which you tell what the to be used Catalog is.
Yes i fixed it :)

Indeed it was the Connection string!

The correct one was (provided by the settingsfile) :

C#
@"Data Source=(LocalDB)\v11.0;AttachDbFilename=" + _global._applicationPath 
                                         + @"\APWarenSysDB.mdf;Integrated Security=True;Connect Timeout=30";


Well taht did it :)

To your Question digimanus : This is used once on program launch, the db connection gets then provided to all classes that need it.

But now i got an other issue :/ But i'll first try to fix it my self :)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900