检查系统DSN并创建系统DSN(如果不存在) [英] Check for System DSN and create System DSN if NOT Existing

查看:184
本文介绍了检查系统DSN并创建系统DSN(如果不存在)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以帮我吗?
我需要检查系统DSN以确保我与AS400服务人员的ODBC连接,如果不存在特定的DSN,则需要创建系统DSN.
我曾尝试使用Google搜索,但找不到适合我的东西.

顺便说一句,我是编程的新手.任何帮助将不胜感激.
谢谢

can someone please help me with this?
i need to check through the System DSN for my ODBC connection to the AS400 servier and create a System DSN if a particular one does not exist.
i''ve tried googling and have not been able to find anything good for me.

btw, i am quite new to programming. any help will be much appreciated.
thank you

推荐答案

我不熟悉AS400,但我希望下面的代码对您有所帮助.
您可以在以下代码中提到的相同注册表位置中查看创建的DSN.


Im not familier with AS400 but i hope below code might help U.
you can view the created DSNs in the same registry locations mentioned in below code.


public void CreateDSN(string dsnName, string description, string server, string driverName, bool trustedConnection, string database, string username)
 {
     RegistryKey DSNKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\", true);

     RegistryKey DSNSubKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources", true);

     DSNKey.CreateSubKey(dsnName);

     RegistryKey DSNValuesKey = Registry.LocalMachine.OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\" + dsnName + "\\", true);
     DSNValuesKey.SetValue("Database", database);
     DSNValuesKey.SetValue("Description", description);
     DSNValuesKey.SetValue("Driver", driverName);
     DSNValuesKey.SetValue("LastUser", database);
     DSNValuesKey.SetValue("Server", server);

     RegistryKey DSNValuesKey2 = Registry.LocalMachine.OpenSubKey("SOFTWARE\\ODBC\\ODBC.INI\\ODBC Data Sources\\", true);
     DSNValuesKey2.SetValue(dsnName, "Sql server");


 }



如果需要更多信息,请还原.



do revert back if you need further info.


这篇关于检查系统DSN并创建系统DSN(如果不存在)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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