连接路径 [英] Connection Path

查看:66
本文介绍了连接路径的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



大家好,


我正在做一个win应用程序,我需要访问微软访问数据库,但路径下面给出了一个异常,找不到数据库,所以任何人都让我知道如何给出路径,如果我们在任何驱动器
中安装安装文件,数据库应该检测到。


 


public static string appath = @" path \Data.mdb" ;; OdbcConnection con = new OdbcConnection(" Driver = {Microsoft Access Driver(* .mdb)}; Dbq =" + appath +" ;; User Id =; Password =;");

解决方案

您可以将数据库文件保存在应用程序文件夹中,并将Application.StartupPath用作appPath

 public static string appath = System.IO.Path.Combine(Application.StartUpPath," Data.mdb"); 
OdbcConnection con = new OdbcConnection(" Driver = {Microsoft Access Driver(* .mdb)}; Dbq =" + appath +" ;; User Id =; Password =;");

您还可以通过以下链接检查您的连接字符串


http://www.connectionstrings.com/access



Hi All,

I \'m doing a win application where i need to access the microsoft access database, but the path given below throws an exception that database is not found, so anybody let me know how to give the path, and also if we install the setup file in any drives , the databse should detect.

 

public static string appath = @"path \Data.mdb"; OdbcConnection con = new OdbcConnection(" Driver={Microsoft Access Driver (*.mdb)};Dbq=" + appath + ";User Id=;Password=;");

解决方案

You can save the database file in your application folder and use Application.StartupPath as appPath

public static string appath = System.IO.Path.Combine(Application.StartUpPath,"Data.mdb"); 
OdbcConnection con = new OdbcConnection(" Driver={Microsoft Access Driver (*.mdb)};Dbq=" + appath + ";User Id=;Password=;");

Also you can check for your connection string from following link

http://www.connectionstrings.com/access


这篇关于连接路径的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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