Red Gate forums :: View topic - Help on SQLConfigDataSource
Return to www.red-gate.com RSS Feed Available

Search  | Usergroups |  Profile |  Messages |  Log in  Register 
Go to product documentation
PInvoke.Net
PInvoke.Net forum

Help on SQLConfigDataSource

Search in PInvoke.Net forum
Post new topic   Reply to topic
Jump to:  
Author Message
rvsraghu



Joined: 10 Jan 2009
Posts: 1

PostPosted: Sun Jan 11, 2009 7:23 am    Post subject: Help on SQLConfigDataSource Reply with quote

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
Back to top
View user's profile Send private message
Display posts from previous:   
Reply to topic All times are GMT + 1 Hour
Page 1 of 1

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group