Click here to Skip to main content
15,918,808 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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
Posted

1 solution

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.


C#
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.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900