Help on SQLConfigDataSource

Announcements and discussion for PInvoke

Moderators: Luke Jefferson, Robert

Help on SQLConfigDataSource

Postby rvsraghu » Sun Jan 11, 2009 7:23 am

Hi,
I am trying to create a User DSN / System DSN using the PInvoke SQLConfigDataSource.

using System.Runtime.InteropServices;
[DllImport("ODBCCP32.DLL",CharSet=CharSet.Unicode, SetLastError=true)]
static extern bool SQLConfigDataSourceW(UInt32 hwndParent , RequestFlags fRequest, string lpszDriver, string lpszAttributes);

private enum RequestFlags : int
{
ODBC_ADD_DSN = 1,
ODBC_CONFIG_DSN = 2,
ODBC_REMOVE_DSN = 3,
ODBC_ADD_SYS_DSN = 4,
ODBC_CONFIG_SYS_DSN = 5,
ODBC_REMOVE_SYS_DSN = 6,
ODBC_REMOVE_DEFAULT_DSN = 7
}

private bool CreateSystemDSN()
{
string vAttributes = "DSN=TestUserDSN" + Convert.ToChar(0);
vAttributes += "Description=Test SQL Server" + Convert.ToChar(0);
vAttributes += "Trusted_Connection=yes" + Convert.ToChar(0);
vAttributes += "Server=192.168.1.2" + Convert.ToChar(0);
vAttributes += "Database=TestDB" + Convert.ToChar(0);
vAttributes += "Uid=sa" + Convert.ToChar(0);
vAttributes += "pwd=password" + Convert.ToChar(0);

try
{

if (SQLConfigDataSourceW(0, RequestFlags.ODBC_ADD_DSN, "SQL Server", vAttributes) == false)
{
MessageBox.Show("Failed to create ODBC data source!!");
return false;
}
}
catch (Exception ex)
{
MessageBox.Show("Failed to create ODBC data source!! \\n" + ex.Message);
}
return true;
}


I was not able to create a DSN when i was sending UID and password, could you please help me out in this issue.

Thanks & Regards,
Raghuram
rvsraghu
 
Posts: 1
Joined: Sat Jan 10, 2009 10:23 pm

Return to PInvoke.Net

Who is online

Users browsing this forum: No registered users and 0 guests