[DllImport("ODBCCP32.DLL",CharSet=CharSet.Unicode, SetLastError=true)]
static extern int SQLConfigDataSource (int hwndParent, int fRequest, string lpszDriver, string lpszAttributes);
TODO
fRequest:
ODBC_ADD_DSN
ODBC_CONFIG_DSN
ODBC_REMOVE_DSN
ODBC_ADD_SYS_DSN
ODBC_CONFIG_SYS_DSN
ODBC_REMOVE_SYS_DSN
ODBC_REMOVE_DEFAULT_DSN
lpszAttributes:
Supports Name value pairs.
None.
Please add some!
public static bool CreateSQLDSN(string dsnName, string serverName, string dbName)
{
string Driver;
string attribs;
Driver = "SQL Server";
attribs = "SERVER=" + serverName + Convert.ToChar(0);
attribs = attribs + "DESCRIPTION=Test DSN" + Convert.ToChar(0);
attribs = attribs + "DSN=" + dsnName + Convert.ToChar(0);
attribs = attribs + "DATABASE=" + dbName + Convert.ToChar(0);
attribs = attribs + "Trusted_Connection=yes" + Convert.ToChar(0);
int intRet = win32apis.SQLConfigDataSource(0, win32apis.ODBC_ADD_DSN, Driver, attribs);
if (intRet == 1)
return true;
return false;
}
internal class win32apis
{
internal const int ODBC_ADD_DSN = 1;
[DllImport("ODBCCP32.DLL",CharSet=CharSet.Unicode)]
internal extern static int SQLConfigDataSource (int hwndParent, int fRequest, string lpszDriver, string lpszAttributes);
}
Do you know one? Please contribute it!