应用程序文件夹中的C#数据库 [英] c# database in application folder

查看:59
本文介绍了应用程序文件夹中的C#数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我希望我的数据库位于应用程序文件夹中,以便它可以移植,即它可以在任何计算机上运行而无需将数据库还原到所有计算机.如果可以,SQL数据库是否可以连接到该数据库?

假设我有一个使用数据库的简单应用程序.我想在另一台计算机上运行它,那我该怎么办....

我的意思是它可以从可移动磁盘(笔式驱动器)运行

完成此声明:

sqlconnection con = new sqlconnection("

I want my database to be in application folder so that it becomes portable i.e it could run on any computer without restoring the database to all computer. is it possible with SQL database if so what would be the code to connect to it.

suppose i have a simple application that uses a database . and i want to run it on another computer then what should i do....

i mean it to run from removable disk ( pen drive )

complete this statement :

sqlconnection con= new sqlconnection ("

推荐答案

您可以使用附加的数据库.

您可以将SQL数据库添加到您的项目中.

并在配置文件中将连接字符串作为

Server =.\ SQLExpress; AttachDbFilename = | DataDirectory | mydbfile.mdf; Database = dbname; Trusted_Connection =是;

参考: http://www.connectionstrings.com/sql-server-2005 [
You can use attached database.

You can add SQL Database into your project.

And in the configuration file put the the connection string as

Server=.\SQLExpress;AttachDbFilename=|DataDirectory|mydbfile.mdf; Database=dbname;Trusted_Connection=Yes;

Reference: http://www.connectionstrings.com/sql-server-2005[^]


尝试以下操作: http://www.mikeduncan.com/sqlite-on-dotnet-in-3-mins/ [ ^ ]
或这样: http://code.google.com/p/sqlite-net/ [ ^ ]
Try this : http://www.mikeduncan.com/sqlite-on-dotnet-in-3-mins/[^]
or this : http://code.google.com/p/sqlite-net/[^]


这篇关于应用程序文件夹中的C#数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆