Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_vb thread: dsn through code


Message #1 by Greg Partin <GPartin@c...> on Fri, 21 Sep 2001 14:03:30 -0400
Unfortunately, the application was already written to use a system DSN.  I'm
assuming there is something I can pass to SQLConfigDataSource as an
attribute that will tell the DSN to use SQL authentication and will allow me
to supply a username and password.  Any other suggestions?  MS has nothing
on this topic.

thanks,
Greg

-----Original Message-----
From: Kim, Cardyin [mailto:CKim@s...]
Sent: Friday, September 21, 2001 2:39 PM
To: professional vb
Subject: [pro_vb] RE: dsn through code


If you are using ADO, you can dynamically configure your
connection source at runtime, by setting the connection
string property of your ADODB.Connection before you open it.

Here are two simple examples of connecting to a SQL Server:

conAllegraSQL.Open "Provider=SQLOLEDB.1;Persist Security " _
    & "Info=True;Data Source=SSSQL001", "myusername", "mypassword"

or

conPGSQL.ConnectionString = "Provider=SQLOLEDB.1;" _
    & "Password=mypassword;" _
    & "Persist Security Info=True;User ID=MyUserName;" _
    & "Initial Catalog=MyDatabaseName;Data Source=MyServerName"
conPGSQL.Open

The first example is a quick open.  The username and password can
be embedded in the connection string, or passed as separate
parameters.  Because I did not specify a database in the connection
string, it will connect to whatever the default database the
user is set to on the server.

In the second example, I just embedded the username and password
in the connection string, and specified the database name.  I also
set the connectionstring separately.

I tend to use the second example because I only keep connections
to the database open when I need to read or write data. So I set
the connection string on Form_Load then when I need them I do the
following:

conPGSQL.Open
'...Recordset processing Here
conPGSQL.Close

Hope this helps you.

Cardyin

---------------------------------------
Cardyin Kim
Client/Server & Web Development Analyst
---------------------------------------


-----Original Message-----
From: Greg Partin [mailto:GPartin@c...]
Sent: Friday, September 21, 2001 11:04 AM
To: professional vb
Subject: [pro_vb] dsn through code


Hi folks,

I'm currently using the windows API SQLConfigDataSource function to create a
system DSN through code.  Instead of using Windows authentication for the
dsn I want to use SQL authentication and supply the username and password.
I also want to be able to specify the default database to use.  Does anyone
know of a way or the command string to send in order to accomplish these 2
items?

Thank you and much obliged,

Greg

  Return to Index