Click to See Complete Forum and Search --> : ADO Data Controls/Connect String


Bud
December 14th, 1999, 09:49 AM
I'm pretty new to VB programming, so I hope this isn't a totally stupid question!

Anyways, I am writing an application to a SQL Server database and have created a login screen to get the username and password for the database. I use the username and password to create a connection string and placed it in the variable strConnectString. The question is: how do I use this variable strConnectString in an ADO Data Control? I have tried placing it in the properties for the ADO Data Control but it doesn't work. I figure I'll have to put in some area of code, but where? I don't want to have to hard code the username and password in the ADO Data Control properties.

Any help most gratefully appreciated!

Bud

Lothar Haensler
December 14th, 1999, 10:20 AM
here is a sample

Dim youruid as string
Dim yourpwd as string
youruid = ' get this from a dialog
yourpwd = ' get this from a dialog
Adodc1.ConnectionString = "DSN=yourDSNgoesHere;uid=" & youruid & ";PWD=" & yourpwd & ";database=yourDatabase"
Adodc1.RecordSource = "select name from sysobjects" ' your recordsource
Adodc1.Refresh



place this code e.g. in a command buttonclick event.
I did NOT set any properties for the data control at runtime.
tested in nt4, vb6, sql 6.5

Bud
December 14th, 1999, 08:17 PM
Lothar,

That was exactly what I needed! I placed the code in the Form_Load() subroutine of the form I had the ADO Data Control in and it worked perfectly.

Many thanks,
Bud