setting adodc cnxn string @ runtime 
Author Message
 setting adodc cnxn string @ runtime

I am writing an app in vb6.  While developing it, I have been using an ado data
control that has been configured to access a SQL Server database.  Everything
works fine.  But now, I want to be able to set the connection string at runtime.  
I removed the connection string in the properties dialog box for the control and
added the following code to the form containing the control:

Private Sub Form_Load()
    Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Persist Security
Info=False;User ID=MyID;Initial Catalog=billing;Data Source=MyServer"
End Sub

This connection string was cut and paste directly from the adodc's properties
dialog box.  But now I get an error message:  [Microsoft][ODBC Driver Manager]
Data Source name not found and no default driver specified

Where did I go wrong?  How can I set the connection string for this control at
runtime?  Thanks in advance for any hints.

Jon



Mon, 16 Jun 2003 06:00:10 GMT  
 setting adodc cnxn string @ runtime
Try first creating a connection object

Set cnn1 = New ADODB.Connection
 cnn1.ConnectionString = "Provider=SQLOLEDB.1;Persist Security
        Info=False;User ID=MyID;Initial Catalog=billing;Data
Source=MyServer"

m_connstring = cnn1.connectionstring

'open the connection
 cnn1.Open

Adodc1.ConnectionString = mconnstring
Adodc1.recordsource = "SELECT...."


I am writing an app in vb6.  While developing it, I have been using an ado
data
control that has been configured to access a SQL Server database.
Everything
works fine.  But now, I want to be able to set the connection string at
runtime.
I removed the connection string in the properties dialog box for the control
and
added the following code to the form containing the control:

Private Sub Form_Load()
    This connection string was cut and paste directly from the adodc's
properties
dialog box.  But now I get an error message:  [Microsoft][ODBC Driver
Manager]
Data Source name not found and no default driver specified

Where did I go wrong?  How can I set the connection string for this control
at
runtime?  Thanks in advance for any hints.

Jon



Mon, 16 Jun 2003 08:09:35 GMT  
 setting adodc cnxn string @ runtime
Thanks Riann.  I tried your suggestion, but it didn't quite work. The
ConnectionString property is read only if the connection is open.  I solved my
problem by disabling the control and running this code:

Private Sub Form_Load()
Dim m_connstring As String

    m_connstring = "Provider=SQLOLEDB.1;Persist Security Info=False;User
ID=MyID;Initial Catalog=billing;Data Source=MyServer"

    'don't open the connection. Connection string property is read only when
connection is open
    Adodc1.ConnectionString = m_connstring
    Adodc1.RecordSource = "SELECT * FROM Services"
    Adodc1.Enabled = True
    Adodc1.Refresh
End Sub

Maybe this can help someone else

Quote:
-----Original Message-----

I am writing an app in vb6.  While developing it, I have been using an ado data
control that has been configured to access a SQL Server database.  Everything
works fine.  But now, I want to be able to set the connection string at runtime.  
I removed the connection string in the properties dialog box for the control and
added the following code to the form containing the control:

Private Sub Form_Load()
    Adodc1.ConnectionString = "Provider=SQLOLEDB.1;Persist Security
Info=False;User ID=MyID;Initial Catalog=billing;Data Source=MyServer"
End Sub

This connection string was cut and paste directly from the adodc's properties
dialog box.  But now I get an error message:  [Microsoft][ODBC Driver Manager]
Data Source name not found and no default driver specified

Where did I go wrong?  How can I set the connection string for this control at
runtime?  Thanks in advance for any hints.

Jon
.



Tue, 17 Jun 2003 00:28:27 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. adodc connection string atr runtime

2. ADODC Connection String Change at Runtime

3. Adding a connection string to an ADODC control at runtime

4. setting adodc database location runtime

5. Setting properties for ADODC during runtime...

6. HOW DO I Set ADODC Connection at Runtime?

7. Please, Can an ADODC be set at runtime?

8. Need Help: Setting ADODC control ConnectString at Runtime

9. Setting ADODC control's datasource at runtime

10. adodc - setting connectstring at runtime

11. Setting ADODC Connection String at run time

12. How to set CR8 connection string during runtime in VB6

 

 
Powered by phpBB® Forum Software