Change connection string problems

Change connection string problems

Post by Frank Butto » Sun, 29 Dec 2002 22:56:09



I an new to VB6 and ADO.  I am trying to connect a form to two different
databases and tables within those DBs.  I am using the DED.  The form is
connected to one db and I am using 2 command controls to do the following
****************************************************************************
************************************
Private Sub cmdByCO_Click()
Dim mDataMember As String
mDataMember = "Company"
' Experiment with changing the connection string
deLocal.cnnLocal.Close
deLocal.cnnLocal.ConnectionString = "C:\Documents and Settings\Button's\My
Documents\My VB Programs\Name Cards\Remote Data\NamesDB.mdb"
deLocal.cnnLocal.Open
'
deLocal.rsCompany.Open
deLocal.rsCompany.Requery
With txtLastName
    Set .DataSource = deLocal
    .DataMember = mDataMember
    .DataField = "LastName"
End With
'
With txtCompany
    Set .DataSource = deLocal
    .DataMember = mDataMember
    .DataField = "Company"
End With
'
ADONavBar1.ADORecordset = deLocal.rsCompany
Me.ADOActionBar1.ADORecordset = deLocal.rsCompany
Me.cmdByCO.Enabled = False
Me.cmdByLN.Enabled = True
'deLocal.rscomOne.Update
'deLocal.cnnLocal.Properties.Refresh
End Sub

Private Sub cmdByLN_Click()
Dim mDataMember As String
mDataMember = "LastName"
' Experiment with changing the connection string
deLocal.cnnLocal.Close
deLocal.cnnLocal.ConnectionString = "C:\Documents and Settings\Button's\My
Documents\My VB Programs\Name Cards\Remote Data\NamesDB.mdb"
deLocal.cnnLocal.Open
'
 deLocal.rsLastName.Open
deLocal.rsLastName.Requery
With txtLastName
    Set .DataSource = deLocal
    .DataMember = mDataMember
    .DataField = "LastName"
End With
'
With txtCompany
    Set .DataSource = deLocal
    .DataMember = mDataMember
    .DataField = "Company"
End With
ADONavBar1.ADORecordset = deLocal.rsLastName
Me.ADOActionBar1.ADORecordset = deLocal.rsLastName
Me.cmdByCO.Enabled = True
Me.cmdByLN.Enabled = False
End Sub
****************************************************************************
***********
I can execute either cmd and the connection string and table will change but
if I try to change back I get an error at the deLocal.rsCompany.Open or the
deLocal.rsLastName.Open .  The error tells me that the action is invalid.

Can anybody help.

Frank Button

 
 
 

Change connection string problems

Post by Veig » Mon, 30 Dec 2002 00:43:55


What you have is not a valid connection string...Heres a trick to help with
the generation of connection strings

1) Create a New text document with no data - In explorer or through a right
click
2) Change the extension of the document to UDL
3) Double click on the UDL file
4) Create and test your connection
5) Open the file in a text editor and you will see a valid connection string

HTH

--
Veign
www.veign.com
<<NEW Link200 v2.0.2 Released>> - Bigger, Better, Cleaner!
www.veign.com/download_application.html#Link200
Code Samples & Sample Projects
http://www.veign.com/information/application/info_app.html
NEW! - Quick Reference Guides
http://www.veign.com/company_store.html
------


Quote:> I an new to VB6 and ADO.  I am trying to connect a form to two different
> databases and tables within those DBs.  I am using the DED.  The form is
> connected to one db and I am using 2 command controls to do the following

****************************************************************************
Quote:> ************************************
> Private Sub cmdByCO_Click()
> Dim mDataMember As String
> mDataMember = "Company"
> ' Experiment with changing the connection string
> deLocal.cnnLocal.Close
> deLocal.cnnLocal.ConnectionString = "C:\Documents and Settings\Button's\My
> Documents\My VB Programs\Name Cards\Remote Data\NamesDB.mdb"
> deLocal.cnnLocal.Open
> '
> deLocal.rsCompany.Open
> deLocal.rsCompany.Requery
> With txtLastName
>     Set .DataSource = deLocal
>     .DataMember = mDataMember
>     .DataField = "LastName"
> End With
> '
> With txtCompany
>     Set .DataSource = deLocal
>     .DataMember = mDataMember
>     .DataField = "Company"
> End With
> '
> ADONavBar1.ADORecordset = deLocal.rsCompany
> Me.ADOActionBar1.ADORecordset = deLocal.rsCompany
> Me.cmdByCO.Enabled = False
> Me.cmdByLN.Enabled = True
> 'deLocal.rscomOne.Update
> 'deLocal.cnnLocal.Properties.Refresh
> End Sub

> Private Sub cmdByLN_Click()
> Dim mDataMember As String
> mDataMember = "LastName"
> ' Experiment with changing the connection string
> deLocal.cnnLocal.Close
> deLocal.cnnLocal.ConnectionString = "C:\Documents and Settings\Button's\My
> Documents\My VB Programs\Name Cards\Remote Data\NamesDB.mdb"
> deLocal.cnnLocal.Open
> '
>  deLocal.rsLastName.Open
> deLocal.rsLastName.Requery
> With txtLastName
>     Set .DataSource = deLocal
>     .DataMember = mDataMember
>     .DataField = "LastName"
> End With
> '
> With txtCompany
>     Set .DataSource = deLocal
>     .DataMember = mDataMember
>     .DataField = "Company"
> End With
> ADONavBar1.ADORecordset = deLocal.rsLastName
> Me.ADOActionBar1.ADORecordset = deLocal.rsLastName
> Me.cmdByCO.Enabled = True
> Me.cmdByLN.Enabled = False
> End Sub

****************************************************************************

- Show quoted text -

Quote:> ***********
> I can execute either cmd and the connection string and table will change
but
> if I try to change back I get an error at the deLocal.rsCompany.Open or
the
> deLocal.rsLastName.Open .  The error tells me that the action is invalid.

> Can anybody help.

> Frank Button


 
 
 

1. Problem while changing the connection string in Data Environment

Dear all,

I've some question while changing connection string in Data
Environment.The situation is that, there are two different Access
file(which contain same tables) for two different user(USER A and USER
B).

The connection string is as follows:

deMain.cnnSeibu.ConnectionString =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + path + ";Persist
Security Info=False"
The path in the connection string will change while using different
user.

The problem is that, when I first use "USER A" database to select the
data on  TABLE A and then I change to use "USER B" database. There is
no problem when I select data on the table other than TABLE A. But
when I also use TABLE A, the error will occur:

run-time error "3709"
The connection cannot be used to perform this operation. It is either
closed or invalid in this context

Why this problem occur?? and what I can do??

Thanks
Alan

2. raw devices

3. Connection: changing connection string in data environment

4. Nantucket's phone number

5. Deploying ADO Data bound controls / changing connection string

6. custom exception number range && jdbc?

7. Why Connection String Change?

8. Paradox 4.5 Corruption

9. connection string change using vb

10. Changing Connection String

11. Changing connection string at runtime

12. Changing connection string on adodc