473,380 Members | 1,346 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,380 software developers and data experts.

Create System DSN for SQL 2000 DB on remote box

Hi,
I've been pulling my hair out trying to write a simple method to
programatically create a system DSN with all parameters on a remote machine.
I have ensured I have the correct permissions on that remote machine. I
have also review many MSDN and codeproject.com articles.

Any help would be great.

Thanks,
Derek
Nov 16 '05 #1
8 2819
DerekS wrote:
Hi,
I've been pulling my hair out trying to write a simple method to
programatically create a system DSN with all parameters on a remote
machine. I have ensured I have the correct permissions on that remote
machine. I have also review many MSDN and codeproject.com articles.

Any help would be great.

Thanks,
Derek


It *is* possible to connect without a DSN, or do you have
specific reasons for using it?

Hans Kesting
Nov 16 '05 #2
Yes.. It must be created.

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:OQ**************@TK2MSFTNGP10.phx.gbl...
DerekS wrote:
Hi,
I've been pulling my hair out trying to write a simple method to
programatically create a system DSN with all parameters on a remote
machine. I have ensured I have the correct permissions on that remote
machine. I have also review many MSDN and codeproject.com articles.

Any help would be great.

Thanks,
Derek


It *is* possible to connect without a DSN, or do you have
specific reasons for using it?

Hans Kesting

Nov 16 '05 #3
Hans,

I assume that you are calling the ConfigDSN function in ODBC.dll (I
think that is the dll)? If so, can you show the declarations, as well as
the call for the function?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DerekS" <ds********@planview.com> wrote in message
news:eO*************@TK2MSFTNGP14.phx.gbl...
Yes.. It must be created.

"Hans Kesting" <ne***********@spamgourmet.com> wrote in message
news:OQ**************@TK2MSFTNGP10.phx.gbl...
DerekS wrote:
> Hi,
> I've been pulling my hair out trying to write a simple method to
> programatically create a system DSN with all parameters on a remote
> machine. I have ensured I have the correct permissions on that remote
> machine. I have also review many MSDN and codeproject.com articles.
>
> Any help would be great.
>
> Thanks,
> Derek


It *is* possible to connect without a DSN, or do you have
specific reasons for using it?

Hans Kesting


Nov 16 '05 #4
Hans,

I think I see part of the problem. Your definition for
SQLConfigDataSource should be:

[DllImport("ODBCCP32.DLL", CharSet=CharSet.Ansi)]
static extern bool SQLConfigDataSource(
IntPtr parent,
[MarshalAs(UnmanagedType.U2)
short request,
string driver,
string attributes);

You had request defined as an int, which was shifting the driver and
attributes parmaeters by two bytes.

I've also updated the definition on pinvoke.net, which was incorrect as
well.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
static extern int This function is used to work with the ODBC Datasources

5/20/2004 2:13:16 PM - sh*************@hotmail.com-131.107.3.92
SQLConfigDataSource (int hwndParent, int fRequest, string lpszDriver, string
lpszAttributes);

VB Signature:
"DerekS" <ds********@planview.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
I've attached the class.

Here's the basic idea.

I have a simple form that gathers:

Server Name

New DSN Name

I know it SQL Server

I know the server is called 'csgsql2000'

and the user/password is 'ip'/'ip'

I know the remote server the DSN is getting created on is called 'CSAPP13'

See small attached from MSDN

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:ub*************@TK2MSFTNGP14.phx.gbl...
Hans,

I assume that you are calling the ConfigDSN function in ODBC.dll (I
think that is the dll)? If so, can you show the declarations, as well as
the call for the function?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DerekS" <ds********@planview.com> wrote in message
news:eO*************@TK2MSFTNGP14.phx.gbl...
> Yes.. It must be created.
>
> "Hans Kesting" <ne***********@spamgourmet.com> wrote in message
> news:OQ**************@TK2MSFTNGP10.phx.gbl...
>> DerekS wrote:
>> > Hi,
>> > I've been pulling my hair out trying to write a simple method to
>> > programatically create a system DSN with all parameters on a remote
>> > machine. I have ensured I have the correct permissions on that
>> > remote
>> > machine. I have also review many MSDN and codeproject.com articles.
>> >
>> > Any help would be great.
>> >
>> > Thanks,
>> > Derek
>>
>> It *is* possible to connect without a DSN, or do you have
>> specific reasons for using it?
>>
>> Hans Kesting
>>
>>
>
>



Nov 16 '05 #5
Great That is getting me closer.... That you SO much. I only have one more
question. I an running this on my local machine however the 'SERVER='
parameter is now correctly showing the correct SQL server, HOWEVER it is
creating this System DSN on my local box. I actually need to remotely
create it on another server that is not the SQL server, and do so from
executing this app from my local box.

Make sense?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP11.phx.gbl...
Hans,

I think I see part of the problem. Your definition for
SQLConfigDataSource should be:

[DllImport("ODBCCP32.DLL", CharSet=CharSet.Ansi)]
static extern bool SQLConfigDataSource(
IntPtr parent,
[MarshalAs(UnmanagedType.U2)
short request,
string driver,
string attributes);

You had request defined as an int, which was shifting the driver and
attributes parmaeters by two bytes.

I've also updated the definition on pinvoke.net, which was incorrect as well.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
static extern int This function is used to work with the ODBC Datasources

5/20/2004 2:13:16 PM - sh*************@hotmail.com-131.107.3.92
SQLConfigDataSource (int hwndParent, int fRequest, string lpszDriver, string lpszAttributes);

VB Signature:
"DerekS" <ds********@planview.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
I've attached the class.

Here's the basic idea.

I have a simple form that gathers:

Server Name

New DSN Name

I know it SQL Server

I know the server is called 'csgsql2000'

and the user/password is 'ip'/'ip'

I know the remote server the DSN is getting created on is called 'CSAPP13'
See small attached from MSDN

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:ub*************@TK2MSFTNGP14.phx.gbl...
Hans,

I assume that you are calling the ConfigDSN function in ODBC.dll (I
think that is the dll)? If so, can you show the declarations, as well as the call for the function?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DerekS" <ds********@planview.com> wrote in message
news:eO*************@TK2MSFTNGP14.phx.gbl...
> Yes.. It must be created.
>
> "Hans Kesting" <ne***********@spamgourmet.com> wrote in message
> news:OQ**************@TK2MSFTNGP10.phx.gbl...
>> DerekS wrote:
>> > Hi,
>> > I've been pulling my hair out trying to write a simple method to
>> > programatically create a system DSN with all parameters on a remote >> > machine. I have ensured I have the correct permissions on that
>> > remote
>> > machine. I have also review many MSDN and codeproject.com articles. >> >
>> > Any help would be great.
>> >
>> > Thanks,
>> > Derek
>>
>> It *is* possible to connect without a DSN, or do you have
>> specific reasons for using it?
>>
>> Hans Kesting
>>
>>
>
>



Nov 16 '05 #6
Hans,

I don't think that the ODBC APIs allow you to create DSN names on remote
machines. Because of this, you will have to create a service that runs on
the other boxes, which you can connect to through remoting, or COM+, or some
other notification mechanism, and run the code on that box.

I am curious, doesn't AD allow for something like this?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DerekS" <ds********@planview.com> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
Great That is getting me closer.... That you SO much. I only have one
more
question. I an running this on my local machine however the 'SERVER='
parameter is now correctly showing the correct SQL server, HOWEVER it is
creating this System DSN on my local box. I actually need to remotely
create it on another server that is not the SQL server, and do so from
executing this app from my local box.

Make sense?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2****************@TK2MSFTNGP11.phx.gbl...
Hans,

I think I see part of the problem. Your definition for
SQLConfigDataSource should be:

[DllImport("ODBCCP32.DLL", CharSet=CharSet.Ansi)]
static extern bool SQLConfigDataSource(
IntPtr parent,
[MarshalAs(UnmanagedType.U2)
short request,
string driver,
string attributes);

You had request defined as an int, which was shifting the driver and
attributes parmaeters by two bytes.

I've also updated the definition on pinvoke.net, which was incorrect

as
well.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
static extern int This function is used to work with the ODBC Datasources

5/20/2004 2:13:16 PM - sh*************@hotmail.com-131.107.3.92
SQLConfigDataSource (int hwndParent, int fRequest, string lpszDriver,

string
lpszAttributes);

VB Signature:
"DerekS" <ds********@planview.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
> I've attached the class.
>
> Here's the basic idea.
>
> I have a simple form that gathers:
>
> Server Name
>
> New DSN Name
>
> I know it SQL Server
>
> I know the server is called 'csgsql2000'
>
> and the user/password is 'ip'/'ip'
>
> I know the remote server the DSN is getting created on is called 'CSAPP13' >
> See small attached from MSDN
>
> "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
> wrote
> in
> message news:ub*************@TK2MSFTNGP14.phx.gbl...
>> Hans,
>>
>> I assume that you are calling the ConfigDSN function in ODBC.dll
>> (I
>> think that is the dll)? If so, can you show the declarations, as well as >> the call for the function?
>>
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - mv*@spam.guard.caspershouse.com
>>
>> "DerekS" <ds********@planview.com> wrote in message
>> news:eO*************@TK2MSFTNGP14.phx.gbl...
>> > Yes.. It must be created.
>> >
>> > "Hans Kesting" <ne***********@spamgourmet.com> wrote in message
>> > news:OQ**************@TK2MSFTNGP10.phx.gbl...
>> >> DerekS wrote:
>> >> > Hi,
>> >> > I've been pulling my hair out trying to write a simple method to
>> >> > programatically create a system DSN with all parameters on a remote >> >> > machine. I have ensured I have the correct permissions on that
>> >> > remote
>> >> > machine. I have also review many MSDN and codeproject.com articles. >> >> >
>> >> > Any help would be great.
>> >> >
>> >> > Thanks,
>> >> > Derek
>> >>
>> >> It *is* possible to connect without a DSN, or do you have
>> >> specific reasons for using it?
>> >>
>> >> Hans Kesting
>> >>
>> >>
>> >
>> >
>>
>>
>
>
>



Nov 16 '05 #7
Not Sure...

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:%2****************@TK2MSFTNGP09.phx.gbl...
Hans,

I don't think that the ODBC APIs allow you to create DSN names on remote machines. Because of this, you will have to create a service that runs on
the other boxes, which you can connect to through remoting, or COM+, or some other notification mechanism, and run the code on that box.

I am curious, doesn't AD allow for something like this?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DerekS" <ds********@planview.com> wrote in message
news:OI**************@TK2MSFTNGP12.phx.gbl...
Great That is getting me closer.... That you SO much. I only have one
more
question. I an running this on my local machine however the 'SERVER='
parameter is now correctly showing the correct SQL server, HOWEVER it is
creating this System DSN on my local box. I actually need to remotely
create it on another server that is not the SQL server, and do so from
executing this app from my local box.

Make sense?

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:%2****************@TK2MSFTNGP11.phx.gbl...
Hans,

I think I see part of the problem. Your definition for
SQLConfigDataSource should be:

[DllImport("ODBCCP32.DLL", CharSet=CharSet.Ansi)]
static extern bool SQLConfigDataSource(
IntPtr parent,
[MarshalAs(UnmanagedType.U2)
short request,
string driver,
string attributes);

You had request defined as an int, which was shifting the driver and attributes parmaeters by two bytes.

I've also updated the definition on pinvoke.net, which was incorrect
as
well.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
static extern int This function is used to work with the ODBC
Datasources
5/20/2004 2:13:16 PM - sh*************@hotmail.com-131.107.3.92
SQLConfigDataSource (int hwndParent, int fRequest, string lpszDriver,

string
lpszAttributes);

VB Signature:
"DerekS" <ds********@planview.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
> I've attached the class.
>
> Here's the basic idea.
>
> I have a simple form that gathers:
>
> Server Name
>
> New DSN Name
>
> I know it SQL Server
>
> I know the server is called 'csgsql2000'
>
> and the user/password is 'ip'/'ip'
>
> I know the remote server the DSN is getting created on is called

'CSAPP13'
>
> See small attached from MSDN
>
> "Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com>
> wrote
> in
> message news:ub*************@TK2MSFTNGP14.phx.gbl...
>> Hans,
>>
>> I assume that you are calling the ConfigDSN function in ODBC.dll
>> (I
>> think that is the dll)? If so, can you show the declarations, as well as
>> the call for the function?
>>
>>
>> --
>> - Nicholas Paldino [.NET/C# MVP]
>> - mv*@spam.guard.caspershouse.com
>>
>> "DerekS" <ds********@planview.com> wrote in message
>> news:eO*************@TK2MSFTNGP14.phx.gbl...
>> > Yes.. It must be created.
>> >
>> > "Hans Kesting" <ne***********@spamgourmet.com> wrote in message
>> > news:OQ**************@TK2MSFTNGP10.phx.gbl...
>> >> DerekS wrote:
>> >> > Hi,
>> >> > I've been pulling my hair out trying to write a simple method

to >> >> > programatically create a system DSN with all parameters on a

remote
>> >> > machine. I have ensured I have the correct permissions on that
>> >> > remote
>> >> > machine. I have also review many MSDN and codeproject.com

articles.
>> >> >
>> >> > Any help would be great.
>> >> >
>> >> > Thanks,
>> >> > Derek
>> >>
>> >> It *is* possible to connect without a DSN, or do you have
>> >> specific reasons for using it?
>> >>
>> >> Hans Kesting
>> >>
>> >>
>> >
>> >
>>
>>
>
>
>



Nov 16 '05 #8
An other approach to this would be to directly edit the registry on the local
machine. Note: This only works for System DSN's.
Here is an example of how to create a SystemDSN for SQL Server:

#using System;
#using Microsoft.Win32
..
..
public class clsODBC
{
private string sDSNName = "";
private string sDB = "";
private string sServer = "";

public clsODBC(string sDSNName, string sDB,string sServer)
{
this.sDSNName = sDSNName;
this.sDB = sDB;
this.sServer = sServer;
}

public bool AddSystemDSN_SQLServer(string sUID, string sPWD)
{
try
{
//create the ODBC Data Source
string sDriver = System.Environment.GetEnvironmentVariable("SystemR oot")
+ @"\System32\SQLSRV32.dll";
RegistryKey oRegKey = Registry.LocalMachine;
oRegKey.OpenSubKey(@"SOFTWARE\ODBC\ODBC.INI",true) .CreateSubKey(sDSNName);
oRegKey.OpenSubKey(@"SOFTWARE\ODBC\ODBC.INI\" +
sDSNName,true).SetValue("Database",sDB);
oRegKey.OpenSubKey(@"SOFTWARE\ODBC\ODBC.INI\" +
sDSNName,true).SetValue("Driver",sDriver);
oRegKey.OpenSubKey(@"SOFTWARE\ODBC\ODBC.INI\" +
sDSNName,true).SetValue("Server",sServer);

if(sUID.Trim() == "*") //if Windows Authentication is used
{
string sLastUser = System.Environment.GetEnvironmentVariable("USERNAM E");
oRegKey.OpenSubKey(@"SOFTWARE\ODBC\ODBC.INI\" +
sDSNName,true).SetValue("Trusted_Connection","Yes" );
oRegKey.OpenSubKey(@"SOFTWARE\ODBC\ODBC.INI\" +
sDSNName,true).SetValue("LastUser",sLastUser);
}
else
{
oRegKey.OpenSubKey(@"SOFTWARE\ODBC\ODBC.INI\" +
sDSNName,true).SetValue("LastUser",sUID);
}

//make the new System DSN visible in the ODBC manager
oRegKey.OpenSubKey(@"SOFTWARE\ODBC\ODBC.INI\ODBC Data
Sources",true).SetValue(sDSNName,"SQL Server");
oRegKey.Close();

return true;
}
catch
{
return false;
}

}
}
"Nicholas Paldino [.NET/C# MVP]" wrote:
Hans,

I think I see part of the problem. Your definition for
SQLConfigDataSource should be:

[DllImport("ODBCCP32.DLL", CharSet=CharSet.Ansi)]
static extern bool SQLConfigDataSource(
IntPtr parent,
[MarshalAs(UnmanagedType.U2)
short request,
string driver,
string attributes);

You had request defined as an int, which was shifting the driver and
attributes parmaeters by two bytes.

I've also updated the definition on pinvoke.net, which was incorrect as
well.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com
static extern int This function is used to work with the ODBC Datasources

5/20/2004 2:13:16 PM - sh*************@hotmail.com-131.107.3.92
SQLConfigDataSource (int hwndParent, int fRequest, string lpszDriver, string
lpszAttributes);

VB Signature:
"DerekS" <ds********@planview.com> wrote in message
news:uD**************@tk2msftngp13.phx.gbl...
I've attached the class.

Here's the basic idea.

I have a simple form that gathers:

Server Name

New DSN Name

I know it SQL Server

I know the server is called 'csgsql2000'

and the user/password is 'ip'/'ip'

I know the remote server the DSN is getting created on is called 'CSAPP13'

See small attached from MSDN

"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote
in
message news:ub*************@TK2MSFTNGP14.phx.gbl...
Hans,

I assume that you are calling the ConfigDSN function in ODBC.dll (I
think that is the dll)? If so, can you show the declarations, as well as
the call for the function?
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"DerekS" <ds********@planview.com> wrote in message
news:eO*************@TK2MSFTNGP14.phx.gbl...
> Yes.. It must be created.
>
> "Hans Kesting" <ne***********@spamgourmet.com> wrote in message
> news:OQ**************@TK2MSFTNGP10.phx.gbl...
>> DerekS wrote:
>> > Hi,
>> > I've been pulling my hair out trying to write a simple method to
>> > programatically create a system DSN with all parameters on a remote
>> > machine. I have ensured I have the correct permissions on that
>> > remote
>> > machine. I have also review many MSDN and codeproject.com articles.
>> >
>> > Any help would be great.
>> >
>> > Thanks,
>> > Derek
>>
>> It *is* possible to connect without a DSN, or do you have
>> specific reasons for using it?
>>
>> Hans Kesting
>>
>>
>
>



Nov 16 '05 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Prashanth Uppunda | last post by:
Hello, Does anybody have an idea on how to instantiate a DCOM server residing in another machine using C#? Thanks Prashanth
9
by: Marc Miller | last post by:
Hi all, I have 2 dev. machines, the 1st is Win 2000 with .NET 7.0 and the 2nd is XP Pro with .NET 2003. My Web Server is Win 2000 Server with IIS 5.0. I can create a new project on my test...
6
by: David W. Simmonds | last post by:
I know that I can create an Image object by using a path like C:\MyPictures\pic.jpg, but how can I create an Image object by using a path like /MyPictures/pic.jpg where the path is relative to the...
7
by: Peter Afonin | last post by:
Hello, I'm using this code to access a network share from an asp.net page: Dim dir As DirectoryInfo = New DirectoryInfo("\\10.0.0.150\FormLib\") Dim files() As FileInfo = dir.GetFiles("*.eps")...
3
by: Kent | last post by:
I am try to link a SQL 2000 table to Access 2000 using VB.Net 2003 Here is my code: Dim Con As New ADODB.Connection Dim Cat As New ADOX.Catalog Dim tbl As New ADOX.Table ...
3
by: purkka | last post by:
Hi I replaced a Win 2000 Adv server to the Win 2003 Std with Front Page Server Extension and .Net Framework 2.0. FPSE is extended to Default Web Site. Visual Studio 2005: If I create a new web...
0
by: tamayi | last post by:
I have a problem (like most others posting issues on this forum :) ) I have a remote server running Windows XP SP2, with both SQL Server 2005 Express with Advanced Features and SQL 2000...
4
by: Vlad | last post by:
I am having problems using the file.create method within a function that is called when looping through an array of filepaths. If I call my function with a hardcoded file path --C:\Temp.txt the...
1
by: Kerem Gümrükcü | last post by:
Hi, i try to create a remote process with Win32_Process.Create, but the remote machine always retruns 9 as result, which say that the path could not be found. Code seems to be fine, except the...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.