如何自动定位数据库? [英] How to locate database automatically?

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

问题描述

我已经在Visual Studio 2010中使用c#开发了一个数据库应用程序.一切运行良好,但是当我将其安装在任何其他用户PC上或将应用程序移动到PC上的其他文件夹时,应用程序显示错误.无法找到数据库目录.如何使我的应用程序自动检查数据库目录?并相应地更改连接字符串以正确运行应用程序?
请帮助...

I have developed a database application in visual studio 2010 using c#. All is running well but when I install it in any other user pc or move the application to other folder in my pc the application shows error. It cannt locate the database directory.How can i enable my application to check the database directory automatically? and change the connection string accordingly to run the app properly?
pls help...

推荐答案

选项:
1.使用配置(或应用程序设置")
2.从共享文件夹访问数据.
3.始终将数据保留在与主exe相对的位置.
例如:让您的应用程序路径为D:\ MyAppFolder \ myapp.exe
让您的数据路径为D:\ MyAppFolder \ MyData \ SomedatabaseFile.ext
因此,您的数据库可以通过以下方式访问:
Options:
1. Use configuration(or App Settings)
2. Access data from a Shared folder.
3. Always keep data in a relative location to the main exe.
Eg: Let Your application path is D:\MyAppFolder\myapp.exe
Let your data path is D:\MyAppFolder\MyData\SomedatabaseFile.ext
So your DB can be accessed as :
string DBPath = System.IO.Path.Combine(System.IO.Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "MyData\\Somedb.mdb");


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

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