需要帮助自动附加数据库 [英] need help attaching database automatically

查看:79
本文介绍了需要帮助自动附加数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


我有一个现有的数据库,并且无论在安装过程中还是在用户运行我的项目时,我都希望它可以自动附加到我的程序中.我只想完成它(自动附加)

我正在使用C#.NET,数据库的名称为"MyLibraryDataBase".

我认为如果有form_load
,我应该在项目的主页中放置一些代码
,thanks;)

Hi,
I have an existing data base and I want it to be automatically attached to my program, no matter during the installation process or when the user runs my project. I just want it to be done(attached automatically)

I''m using C#.NET and the name of my database is "MyLibraryDataBase".

I think I should put some code in the main page of my project in the event of form_load

,thanks ;)

推荐答案

如果我正确地阅读了此内容,那么您是否希望该软件仅连接到一个数据库?

为什么不将数据库名称设置为文本框字段,其中文本默认为"MyLibraryDataBase",将其传递给变量,该变量随后在代码中用于连接数据库,因此,如果以后您可以随时更改它您是否需要,但如果未指定任何内容,则始终默认为"MyLibraryDataBase"?
if i''m reading this correctly, you are wanting the software to only connect to one database?

Why not set up the database name as a textbox field where the text defaults to "MyLibraryDataBase", pass that to a variable that is then used in your code to connect to your database, that way you can always change it at a later date if you need to but will always default to "MyLibraryDataBase" if nothing is specified?


您可以在配置文件中设置连接字符串.您可以使用它来连接数据库.在我的文章 SqlParameters的劣势变成优势 [
you can set the connection string in your config-file. You can use that to connect to a database. In my article Disadvantages of SqlParameters Turned into Advantages[^] you can find a method that finds your defaultconnection in your config file


如果我错了,我想每个人都在这里遗漏了一个问题,这使我有些纠正,但是您是否正在寻找将该程序发布到多台PC上,然后该程序的每个实例都有自己的数据库?
试试:

http://msdn.microsoft.com/en-us/library/ms228283 (v = vs.80).aspx [
I think everyone''s missing the question here a bit correct me if im wrong but are you looking for publishing the program to multiple PC''s and then each instance of the program has its own database?

try:

http://msdn.microsoft.com/en-us/library/ms228283(v=vs.80).aspx[^]


这篇关于需要帮助自动附加数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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