Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Check for System DSN and create System DSN if NOT Existing (iSeries Access ODBC Driver)
- using System;
- using System.Runtime.InteropServices;
- public class ODBC_Manager
- {
- [DllImport("ODBCCP32.dll")]
- public static extern bool SQLConfigDataSource(IntPtr parent, int request, string driver, string attributes);
- [DllImport("ODBCCP32.dll")]
- public static extern int SQLGetPrivateProfileString(string lpszSection, string lpszEntry, string lpszDefault, string @RetBuffer, int cbRetBuffer, string lpszFilename);
- private const short ODBC_ADD_DSN = 1;
- private const short ODBC_CONFIG_DSN = 2;
- private const short ODBC_REMOVE_DSN = 3;
- private const short ODBC_ADD_SYS_DSN = 4;
- private const short ODBC_CONFIG_SYS_DSN = 5;
- private const short ODBC_REMOVE_SYS_DSN = 6;
- private const int vbAPINull = 0;
- public void CreateDSN(string strDSNName)
- {
- string strDriver;
- string strAttributes;
- try
- {
- string strDSN = "";
- string _server = //ip address of the server
- string _user = //username
- string _pass = //password
- string _description = //not required. give a description if you want to
- strDriver = "iSeries Access ODBC Driver";
- strAttributes = "DSN=" + strDSNName + "