ADO datacontrol question 
Author Message
 ADO datacontrol question

Could someone helpme with the following.

I have created a VB6 app using 3 ADO datacontrols that are bound to a
combo box and several text box's for user input.  The app is
completed, and works fine, except for the hassle of the database path
in the conectionstring.
Is there a way to set the connection string via code with the ado
datacontrol ie: using the "App.path" funciton , to enable the program
to find the access.mdb file wherever the user installs the app?
Note:  I have tried using the
datacontrol.connectionstring = " Provider=Microsoft.Jet.OLEDB.4.0;Data
Source=Demod.mdb;Persist Security Info=False " In my Main() procedure
( which fires off before the form containing the datacontrols is
loaded ), but it still errors out on me.  

Any help would be greatly appreaciated

Thanks

Dave LaPorte

Please feel free to email me





Mon, 10 Nov 2003 04:06:59 GMT  
 ADO datacontrol question
If you make a connection in the adoDataControl
or make a 'Public Sub ConnectToDatabase()' in a module,
what ever you do with code, is the connection that counts.

    With rs
        .ActiveConnection = mdiMain.adoDataControl.ConnectionString
        .Open "Select Distinct Name from All_Limits Where Name<>''"
        If Not .BOF Then .MoveFirst
        Do Until .EOF
            Combo1.AddItem !Name
            .MoveNext
        Loop
    End With

Or

        Set rs = mdiMain.adoDataControl.Recordset
        ' and do what you like if it is so that you have defined
        ' a RecordSource in the properties of the adoDataControl,
        ' or if you have an array of datacontrols that have differnt
        ' connections or recordsources :
         Set rsP = mdiMain.adoDataControl(0).Recordset
         Set rsQ = mdiMain.adoDataControl(1).Recordset

The Sub:
Public Sub Connect()
    On Error GoTo Feil
    strUserId = GetSetting("Testrapporter", "Connection", "Text(1)", "sa")
    strProvider = GetSetting("Testrapporter", "Connection", "Provider",
"SQLOLEDB")
    strInitCat = GetSetting("Testrapporter", "Connection", "InitCat",
"Prod")
    strServer = GetSetting("Testrapporter", "Connection", "Server",
"MsSQLserver")
    If strProvider = "Microsoft.Jet.OLEDB.4.0" Then
        FindDataBase (strInitCat)
        If Avbryt Then frmConnect.Show vbModal
        Set con = New ADODB.Connection
        With con
            .Provider = strProvider
            .ConnectionString = frmForm.commondg1.FileName
            .Open
        End With
        Access = True
        TilKoblet = True
        frmForm.SBar1.Panels(3).Text = "  Connected to " & strInitCat
        Exit Sub
    Else
        Access = False
        Avbryt = False
    End If
    Set con = New ADODB.Connection
    With con
        .ConnectionTimeout = 30
        .Provider = strProvider    'SQLOLEDB
        .CursorLocation = adUseClient
        .ConnectionString = "Server=" & strServer & ";" & "User Id=" _
                            & strUserId & ";" & "Password=" _
                            & strPassWord & ";" & "Initial Catalog=" &
strInitCat & ";Workstation ID=''"
        .Open
    End With
    TilKoblet = True
    Exit Sub
Feil:
   If Err.Number <> -2147467259 Or Avbryt Then FindDataBase (strInitCat)
    MsgBox Err.Description & " Number: " & Err.Number, vbInformation,
"Connection error"
    frmConnect.Show vbModal
End Sub

Public Function FindDataBase(fil As String) As String
    On Error GoTo Feil
    With frmForm.commondg1
        .DialogTitle = "Find " & fil
        .DefaultExt = "*.*"
        .FileName = fil
        If LCase(Right(fil, 4)) = ".mdb" Then Access = True
        If Access Then
         .InitDir = GetSetting("Testrapporter", "Connection", "InitDir1",
"G:\generator")
         .Filter = "(*.MDB)|*.mdb;(All files *.*)|*.*"
        End If
        .CancelError = True
        .ShowOpen
        If Right(.FileName, 4) = ".mdb" Then
            Do While UCase(Right(Trim(.FileName), 13)) <> "GENERATOR.MDB"
               MsgBox "File Name is not equal to Generator.mdb"
               .ShowOpen
            Loop
        End If
        fil = .FileName
        If Access Then
            SaveSetting "Testrapporter", "Connection", "InitDir1", .InitDir
        End If
        SaveSetting "Testrapporter", "Connection", "InitCat", .FileName
    End With
    Exit Function
Feil:
    If Err.Number = 32755 Then Avbryt = True
    MsgBox Err.Description
End Function

Quote:
> Could someone helpme with the following.

> I have created a VB6 app using 3 ADO datacontrols that are bound to a
> combo box and several text box's for user input.  The app is
> completed, and works fine, except for the hassle of the database path
> in the conectionstring.
> Is there a way to set the connection string via code with the ado
> datacontrol ie: using the "App.path" funciton , to enable the program
> to find the access.mdb file wherever the user installs the app?
> Note:  I have tried using the
> datacontrol.connectionstring = " Provider=Microsoft.Jet.OLEDB.4.0;Data
> Source=Demod.mdb;Persist Security Info=False " In my Main() procedure
> ( which fires off before the form containing the datacontrols is
> loaded ), but it still errors out on me.

> Any help would be greatly appreaciated

> Thanks

> Dave LaPorte

> Please feel free to email me






Mon, 10 Nov 2003 06:10:44 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. VB6 and ADO datacontrol question

2. ADO datacontrol question

3. ADO DataControl Question

4. when datacontrol.refresh after datacontrol.recordsource=sql, I get object error

5. ADO DataControl + DataGrid Control

6. Connecting ADO Datacontrol and Datagrid to Foxpro Table

7. ADO Datacontrol and Access password

8. Q:Sorting A Grid Bound To A Ado DataControl Using A Parameter'd Stored Procedure

9. Use ADO from VB5 with DataControl-based forms

10. Assigning Recordset created with ADO to VB5 DataControl ?

11. VB6 Rebind Datagrid to ADO DataControl

12. ADO DataControl in Usercontrol

 

 
Powered by phpBB® Forum Software