如何在另一个网络中动态更改数据库文件的位置我... [英] How to change the location of database file dynamically in another networkhow do I...

查看:139
本文介绍了如何在另一个网络中动态更改数据库文件的位置我...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Windows窗体应用程序中工作c#visual studio 2015连接到数据库

access 2007



我的连接如下所示/>


I work in windows form application works in c# visual studio 2015 connect to database
access 2007

my connection as bellow

public static string fileName = @"\\192.168.1.30\data\accessqr.accdb";
 public string connection = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;" + "Data Source={0}", fileName);





它没有任何问题工作



但如果我需要在另一个网络中移动数据库访问文件accessqr.accdb或



另一个地方



可能没有ip 192.168.1.30可用或没有驱动器D:可用以便



如何使连接动态接受任何网络?



以便我需要我的连接动态,适合任何地方

我做什么?




我尝试过:





it working without any problem

but if i need to move database access file accessqr.accdb in another network or

another place

may be no ip 192.168.1.30 available or no drive D: available so that

how to make connection dynamic to accept any network ?

so that i need my connection dynamic and is suitable to any place
what i do ?


What I have tried:

how to change the location of database file dynamically in another networkHow do I...

推荐答案

将您的连接字符串存储在应用程序的配置文件中:

连接字符串和配置文件 [ ^ ]

< a href =https://msdn.microsoft.com/en-us/library/ms178411.aspx>如何:从Web.config文件中读取连接字符串 [ ^ ]

如何从C#中的App.Config获取连接字符串 [< a href =https://www.codeproject.com/Tips/416198/How-to-get-Connection-String-from-App-Config-inCstarget =_ blanktitle =New Window> ^ ]



这样,你就不需要了如果移动数据库则重新编译。
Store your connection string in the application's configuration file:
Connection Strings and Configuration Files[^]
How to: Read Connection Strings from the Web.config File[^]
How to get Connection String from App.Config in C#[^]

That way, you won't need to recompile if you move the database.


这篇关于如何在另一个网络中动态更改数据库文件的位置我...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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