How to create DSN for SQL Server using C# ?

Posted by Pavan Kumar on Stack Overflow See other posts from Stack Overflow or by Pavan Kumar
Published on 2010-05-16T14:19:27Z Indexed on 2010/05/16 14:20 UTC
Read the original article Hit count: 434

Filed under:
|
|
|

using Microsoft.Win32; using System.Runtime.InteropServices;

[DllImport("ODBCCP32.dll")] private static extern bool SQLConfigDataSource(IntPtr parent, int request, string driver, string attributes);

private void btnDsn_Click(object sender, EventArgs e) {

string str = "SERVER=MYDBSERVER\0DSN=MYDSN\0DESCRIPTION=MYDSNDESC\0DATABASE=master\0TRUSTED_CONNECTION=YES"; SQLConfigDataSource((IntPtr)0, 4, "SQL Server ",str);

}

Reference : http://social.msdn.microsoft.com/Forums/en-US/vscrystalreports/thread/441811b9-c4e9-4d15-97a3-7b92d2c9f318

Can anybody help me remove the following errors??

Error 1 Expected class, delegate, enum, interface, or struct C:\Documents and Settings\Pavan\My Documents\Visual Studio 2008\Projects\CopyDatabase\CopyDatabase\Synchronize.cs 17 23 CopyDatabase

Error 2 The name 'SQLConfigDataSource' does not exist in the current context C:\Documents and Settings\Pavan\My Documents\Visual Studio 2008\Projects\CopyDatabase\CopyDatabase\Synchronize.cs 67 13 CopyDatabase

© Stack Overflow or respective owner

Related posts about create

Related posts about dsn