日期:2014-05-19  浏览次数:20748 次

在程序里自定义配置数据源
自己开发一个客户端的WinForm程序,想能够自己实现配置多种数据源,并为客户提供一个可视化的界面,就像.net环境下连接数据库那样有向导界面,因为客户端的数据库是未知的,可能是文本文件,FoxPro,excel,access,sqlserver,oracle,sybase,DB2等等,向导配置完成后,把连接字串保存到数据库或者XML以备下次运行读取,请问该如何做啊?谢谢了!

------解决方案--------------------
// Get the count of the connection strings.
int connStrCnt =
ConfigurationManager.ConnectionStrings.Count;

// Define the string name.
string csName = "ConnStr " +
connStrCnt.ToString();

// Get the configuration file.
System.Configuration.Configuration config =
ConfigurationManager.OpenExeConfiguration(
ConfigurationUserLevel.None);

// Add the connection string.
ConnectionStringsSection csSection =
config.ConnectionStrings;
csSection.ConnectionStrings.Add(
new ConnectionStringSettings(csName,
"LocalSqlServer: data source=127.0.0.1;Integrated Security=SSPI; " +
"Initial Catalog=aspnetdb ", "System.Data.SqlClient "));

// Save the configuration file.
config.Save(ConfigurationSaveMode.Modified);

------解决方案--------------------
用Combobox控件将选项写入
------解决方案--------------------
同关注解决
------解决方案--------------------
利用ADO.NET 2.0提供的公共接口,编写一组适用于多种数据库配置的通用代码,达到灵活配置不同种类的数据库目的,并将配置信息以加密的形式保存在INI文件中,既增强了系统的安全性,又便于系统管理人员的管理。另外,将数据库配置功能封装成组件,有利于组件的扩充和无缝升级。......
上面是《Visual Basic.net 2005 数据库编程技术与实例》第五章的“数据库配置组件DBConfig设计” 一节要解决的内容,建议你参考本书,全程教你如何设计数据库配置组件。
------------------------------------------
我的书《Visual Basic .NET 2005数据库编程技术与实例》已由人民邮电出版社出版
人民邮电出版社出版:http://www.ptpress.com.cn/books/Book_Information.asp?BID=16271
中国互动出版网:http://www.china-pub.com/computers/common/info.asp?id=35208
------------------------------------------