简体   繁体   中英

C# application using a Local database with stored procedures

I am trying to develop a simple C# application which use a database. I am currently using MS Server 2008 , but I found a portability issue since running the application on different computers would require MS Server to be installed. Also, my database makes use of stored procedures.

What other database types I can use in order to overcome this problem (nb it must use stored procedures)?

If I am to use MS Server 2008, assuming it is installed on every pc, how can I copy my .mdf file in order to be accessible? (ie install it on application load ?)

UPDATE

From this website , I found the following connection string :

Attach a database file on connect to a local SQL Server Express instance ...

Server=.\SQLExpress;AttachDbFilename=c:\asd\qwe\mydbfile.mdf;Database=dbname; Trusted_Connection=Yes;

I presume that this will copy the .mdf file from my folder. Hence, I am using the following connection string but to no success ...

Server=.\SQLExpress;AttachDbFilename=...... database path.... ;Database=TrieDB.mdf; Trusted_Connection=Yes;

Directory lookup for the file "... database path... " failed with the operating system error 5(Access is denied.).
Cannot attach the file '... database path...' as database 'TrieDB.mdf'

Most "certified" database engines requires you to actually install the engine.
Most "certified" database engines enable the use of stored procedures.

In order to have the .mdf file on more machines you can simply copy it and afterwards use the sql management studio to attach the file to the engine, but that is not an ideal solution if you planning to distribute your application in many places, the ideal solution will be to create an installation package and fix that it is automaticlly being done from the installation and undone when you uninstall.

imho: You insist on stored procedure with a de-centeralized solution - do notice that this is a rather rare tactic - it has the smell of a wrong path.. But I can't be sure unless you provide some more information.

There are really two general designs to do something like what you're describing. Either have a centralized database that all copies of the application (and/or multiple applications) access, or create an installation package complete with the database (which is generally only accessed by a single application).

Personally, if you don't want to, or can't, use a centralized database solution, I would suggest changing your philosophy about stored procedures and looking into SQL Server Compact . I found this article discussing the reasons why SQL Server Compact doesn't have sprocs, which I think will be useful to you, even if you decide you really need them.

That said, if you need to install a database with your app, you can create a setup package within Visual Studio, of you could also look into using WiX .

您可以分离数据库,复制并附加目标数据库上的mdf文件。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM