Setting adodc connection string at runtime?

Setting adodc connection string at runtime?

Post by Jon » Fri, 29 Dec 2000 05:46:39



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

 
 
 

Setting adodc connection string at runtime?

Post by Jon » Sat, 30 Dec 2000 01:23:13


Figured it out. here it is if anyone is interested.

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

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

.


 
 
 

Setting adodc connection string at runtime?

Post by Lance Marran » Thu, 04 Jan 2001 08:16:41


The error is actually coming when the control tries to use the RecordSource
information to get data when the form is loaded.  I found that I had to
leave both the connection string and the RecordSource properties blank at
design time and then change them at run-time when I needed them.
P.S.  Don't forget to refresh after setting the two properties.

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

 
 
 

1. 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

2. SQL and variables problem in VB

3. adodc connection string atr runtime

4. Looking for someone to help me with Approach97

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

6. !US - Redmond, WA - Systems Analyst II - Oracle

7. HOW DO I Set ADODC Connection at Runtime?

8. Shutting down NT system. Is DB shutdown or crashed?

9. Setting ADODC Connection String at run time

10. Setting properties for ADODC during runtime...

11. Need Help: Setting ADODC control ConnectString at Runtime

12. adodc - setting connectstring at runtime