系统管理员质量保证SQL Server 2000Windows Vista数据库管理员Windows 2003OracleADO.NETWindows XPXML.NET 3.5SQL Server 2005初学者中级开发SQL ServerWindows.NETC#
多数据库连接文件管理器
用于管理应用程序的多个数据库连接字符串的实用工具。
引言
此应用程序旨在与现有程序集成,或成为将利用到 Oracle 和 SQL Server 数据库平台的多个数据库连接的新项目的 Shell。
背景
许多应用程序使用数据库作为后端数据源。在这样做时,需要连接到多个数据库,尤其是在 QA 方面。客户也喜欢无需编辑 XML 或文本配置文件即可编辑连接,因为这些文件非常复杂且缺乏技术知识。 我最初创建它是作为我正在测试的软件包的数据生成实用程序的 Shell。 最后,我使用了我们现有的 DAL,所以我把它搁置了。 我觉得我投入的努力可以节省别人的时间,所以它就在这里。
使用代码
代码在大多数领域都很简单,并且记录得很好。 我想说 XML / XPath 部分有点复杂。 我要感谢 Michael Chao,因为我使用了他在 CodeProject 中的一个程序作为编辑 XML 连接文件的起始基础。 他的文章可以在这里找到
这是一个用于创建新连接(字符串)的代码片段
// Here is an example of the Create Connection Method using XML
private void CreateConnectionInXML()
{
string FileNameNew = DataConnection.ConnectionFileLocation;
// Determine Selected DB Type and set variable to write to xml
int dbtypenew;
if (comboBoxDBType.SelectedIndex == 0)
dbtypenew = 1;
else
dbtypenew = 2;
try
{
// Create an XML Reader, Open Document, Read, Close Reader
XmlTextReader reader = new XmlTextReader(FileNameNew);
XmlDocument docnew = new XmlDocument();
docnew.Load(reader);
reader.Close();
XmlNode currNode;
XmlDocumentFragment docFrag = docnew.CreateDocumentFragment();
docFrag.InnerXml = "<connection>" +
"<title>" + textBoxConnTitle.Text + "</title>" +
"<server>" + textBoxServerName.Text + "</server>" +
"<database>" + textBoxDatabaseName.Text + "</database>" +
"<dbtype>" + dbtypenew + "</dbtype>" +
"<username>" + textBoxUsername.Text + "</username>" +
"<password>" + textBoxPassword.Text + "</password>" +
"</connection>";
currNode = docnew.DocumentElement;
currNode.InsertAfter(docFrag, currNode.LastChild);
//save the output to a file
docnew.Save(FileNameNew);
this.DialogResult = DialogResult.OK;
}
catch (Exception ex)
{
MessageBox.Show("Exception: {0}", ex.ToString());
this.DialogResult = DialogResult.Cancel;
}
}
该程序是用 Visual Studio 2008 为 .NET 3.5 编写的。 我相信它可以被修改为与较低的版本一起使用。
这里有一些截图
主窗体
编辑表单
关注点
我想说这是我在学校之外的第一个编码项目。 我仍然在开发我正在创建的主要工具,并且希望我可以在这里展示它,但由于商业原因而不能。 我希望这对某人有帮助,并欢迎任何反馈,因为我才刚刚开始从事软件开发领域。
历史
- 版本 1.0。