连接和使用.mdf DatabaseFile [英] Connecting and using a .mdf DatabaseFile
问题描述
嘿大家,
我正在为我的桌面俱乐部开发一个小项目,它需要一个数据库来存储我们商店的库存。因此,我想使用可以在VS中创建的本地数据库。
问题是,我用VS2012来创建项目,做了所有的东西来运行.sdf数据库。当我现在改为VS 2013时,.sdf DBFile不再存在,因为我不确定DB所需的大小我改为.mdf DB文件。
我现在无法使用我的代码获得与此.mdf DatabaseFile的连接,但可以通过datasourcemanager / Serverexplorer访问它。
所以我要求的是一个线索,如果我需要使用类似于sqlCe的somithing或者是否正在使用通常的SQL类。我现在非常绝望,因为我搜索了大量关于正确连接字符串的论坛,我仍然得到相同的错误,服务器以某种方式关闭或无法访问。
那么,我怎么用这个本地数据库? CE的东西看起来很简单!
提前谢谢。
顺便说一句,连接字符串:(据我所知)
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)
Data Source=(LocalDB)\v11.0;AttachDBFilename="Path\Database.mdf";Integrated Security=true;
推荐答案
你错过了V!
You are missing the V!
Data Source=(LocalDB)\v11.0;AttachDBFilename="Path\Database.mdf";Integrated Security=true;
是的我修好了它。
确实是连接字符串!
正确的是(由设置文件提供):
Yes i fixed it :)
Indeed it was the Connection string!
The correct one was (provided by the settingsfile) :
@"Data Source=(LocalDB)\v11.0;AttachDbFilename=" + _global._applicationPath
+ @"\APWarenSysDB.mdf;Integrated Security=True;Connect Timeout=30";
好吧做到了:)
给你的问题digimanus:这个在程序启动时使用一次,然后将db连接提供给所有需要它的类。
但现在我还有另一个问题:/但我会先试着修理我自己:)
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 :)
这篇关于连接和使用.mdf DatabaseFile的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!