Getting error while loading database connection-VBForums
Results 1 to 10 of 10

Thread: Getting error while loading database connection

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    8

    Getting error while loading database connection

    Can anyone help me for the error.
    Below is my code
    Run-time error '-2147467259 (80004005)': [Microsoft][ODBC Microsoft Access Driver] Could not find file '(unknown)'.
    Code:
    Private Sub cmdApply_Click()
    
        Text3.Text = "INDIA"
        Map1.Layers.Clear
        ListView1.ListItems.Clear
        ListView1.ColumnHeaders.Clear
          
        Set c = New Connection
        Set cm = New Command
        Set r = New Recordset
    'On Error Resume Next
    
        strconn = "Driver={Microsoft Access Driver (*.mdb)};" & _
         "Dbq =" & App.path & "\Vul_all_param_Project.mdb;" & _
         "Uid=Admin; Pwd="
    'Vul_all_param_Project.mdb
        c.Open strconn
    
        r.LockType = adLockBatchOptimistic
        r.CursorLocation = adUseClient
        r.CursorType = adOpenDynamic
    
        dc.Database = App.path
        If Combo1.Text = "" Then
            MsgBox "SELECT THE APPROPRIATE PARAMETER FOR ADAPTIVE_CAPACITY FROM ATTRIBUTES COMBO BOX", vbDefaultButton1, "SELECT"
        End If
        
        If Combo1.Text = "Electricity" Then
           Combo1.Text = "Electricit"
        
             
            If Not dc Is Nothing Then
               Set gds1 = dc.FindGeoDataset("Vul_all_param_Project")
               Set gds2 = dc.FindGeoDataset("India_state")
               'Set gds3 = dc.FindGeoDataset("India_state")
            'End If
     
            If Not lyr1 Is Nothing Then
             If Not lyr2 Is Nothing Then
             
               
               Set lyr1 = New MapObjects2.MapLayer
               Set lyr1.GeoDataset = gds1
               Set lyr2 = New MapObjects2.MapLayer
               Set lyr2.GeoDataset = gds2
           '    Set lyr3 = New MapObjects2.MapLayer
            '   Set lyr3.GeoDataset = gds3
               
         '    End If
          '  End If
       
            lyr2.Symbol.Color = moWhite
            lyr2.Symbol.OutlineColor = moBlack
            lyr2.Symbol.Size = 2
            'lyr2.Symbol.Style = moTransparent
            
            
            Set recs = lyr1.Records
        
            Call PopulateNewCBlegend(Combo1.Text)
            cmdApply.Enabled = True
            Call ApplyClassBreaks
            legend1.LoadLegend True
            Map1.Refresh
            ListView1.ColumnHeaders.Clear
            ListView1.ListItems.Clear
            
            
            Map1.Layers.Add lyr2
            Map1.Layers.Add lyr1
          '  Map1.Layers.Add lyr3
        
            legend1.setMapSource Map1
            legend1.LoadLegend True
            
            MsgBox "This parameter gives the Rural Electrification as a % of Number of Villages with electric supply in relation to total number of Villages", vbExclamation, "Electricity"
            
            Set rs = New Recordset
        
     '12345  Map1.Refresh
             ListView1.ColumnHeaders.Clear
             ListView1.ListItems.Clear
            'should display the tablular data
         
            Set colheader = ListView1.ColumnHeaders.Add()
             
             ListView1.ColumnHeaders.Add(1) = "ID"
             ListView1.ColumnHeaders.Add(2) = "Dist_ID"
             ListView1.ColumnHeaders.Add(3) = "COUNTRY"
             ListView1.ColumnHeaders.Add(4) = "STATE"
             ListView1.ColumnHeaders.Add(5) = "DISTRICT"
             ListView1.ColumnHeaders.Add(6) = "Electricity"
             
                
             'If Combo1.Text = "Electricity" Then
             sql = "select * from Vul_all_param_Project order by DIST_ID"
             rs.Open sql, c
                 While rs.EOF = False
                   Set l = ListView1.ListItems.Add(, , Trim(rs(0)) & "")
                   l.SubItems(1) = Trim(rs(5) & "")
                   l.SubItems(2) = Trim(rs(6) & "")
                   l.SubItems(3) = Trim(rs(3) & "")
                   l.SubItems(4) = Trim(rs(2) & "")
                   l.SubItems(5) = Trim(rs(64) & "")
                   
                   rs.MoveNext
                 Wend
                 
            End If
            End If
            End If
    ElseIf Combo1.Text = "Fertilizer" Then
           Combo1.Text = "tot_fert_k"
    
            If Not dc Is Nothing Then
                Set gds1 = dc.FindGeoDataset("Vul_all_param_Project")
                 If Not gds1 Is Nothing Then
               Set gds2 = dc.FindGeoDataset("India_State")
            'End If
     
            If Not lyr1 Is Nothing Then
             If Not lyr2 Is Nothing Then
               Set lyr1 = New MapObjects2.MapLayer
               Set lyr1.GeoDataset = gds1
               Set lyr2 = New MapObjects2.MapLayer
               Set lyr2.GeoDataset = gds2
         '    End If
          '  End If
           
       
            lyr2.Symbol.Color = moWhite
            lyr2.Symbol.OutlineColor = moBlack
            lyr2.Symbol.Size = 2
    
            Set recs = lyr1.Records
        
            
            Call PopulateNewCBlegend(Combo1.Text)
            cmdApply.Enabled = True
            Call ApplyClassBreaks
            legend1.LoadLegend True
            Map1.Refresh
            ListView1.ColumnHeaders.Clear
            ListView1.ListItems.Clear
            
            Map1.Layers.Add lyr2
            Map1.Layers.Add lyr1
        
            legend1.setMapSource Map1
            legend1.LoadLegend True
            
            
            
            MsgBox "This parameter gives the Fertilizer Consumption of nutrients (N+P+K) per ha of gross sown area", vbInformation, "Fertilizer"
    
            Set rs = New Recordset
       
           ' Map1.Refresh
            ListView1.ColumnHeaders.Clear
            ListView1.ListItems.Clear
            'should display the tablular data
         
            Set colheader = ListView1.ColumnHeaders.Add()
             
             ListView1.ColumnHeaders.Add(1) = "ID"
             ListView1.ColumnHeaders.Add(2) = "Dist_ID"
             ListView1.ColumnHeaders.Add(3) = "COUNTRY"
             ListView1.ColumnHeaders.Add(4) = "STATE"
             ListView1.ColumnHeaders.Add(5) = "DISTRICT"
             ListView1.ColumnHeaders.Add(6) = "Fertilizer"
             
                
             sql = "select * from Vul_all_param_Project order by DIST_ID"
             rs.Open sql, c
                 While rs.EOF = False
                   Set l = ListView1.ListItems.Add(, , Trim(rs(0)) & "")
                   l.SubItems(1) = Trim(rs(5) & "")
                   l.SubItems(2) = Trim(rs(6) & "")
                   l.SubItems(3) = Trim(rs(3) & "")
                   l.SubItems(4) = Trim(rs(2) & "")
                   l.SubItems(5) = Trim(rs(52) & "")
                   
                   rs.MoveNext
                 Wend
                 
          '      pTable.Database = strconn
        
            '    If Combo1.Text = "Fertilizer" Then
             '      pTable.Name = "Fertilizer"
             '   End If
                End If
            End If
        End If
    End Sub

  2. #2
    PowerPoster
    Join Date
    Oct 2013
    Posts
    2,847

    Re: Getting error while loading database connection

    Are you trying to use ODBC to connect to an Access MDB file?
    Better use Microsoft Jet OLE DB 4.0
    Have a look here for alternative connection strings:
    https://www.connectionstrings.com/access/

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    8

    Re: Getting error while loading database connection

    Quote Originally Posted by Arnoutdv View Post
    Are you trying to use ODBC to connect to an Access MDB file?
    Better use Microsoft Jet OLE DB 4.0
    Have a look here for alternative connection strings:
    https://www.connectionstrings.com/access/
    still getting error
    Could not find installable ISAM
    strconn = "Provider={Microsoft.Jet.OLEDB.4.0};" & _
    "Data Source =" & App.path & "\Vul_all_param_Project.mdb;" & _
    "Uid=Admin; Pwd="

  4. #4
    PowerPoster
    Join Date
    Oct 2013
    Posts
    2,847

    Re: Getting error while loading database connection

    Which version of the Access MDB has been used?
    Access 97, 2000, or later?

    Remove the curly braces from the statement -> {}
    Code:
    sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;"

  5. #5

    Thread Starter
    New Member
    Join Date
    Jul 2009
    Posts
    8

    Re: Getting error while loading database connection

    Quote Originally Posted by Arnoutdv View Post
    Which version of the Access MDB has been used?
    Access 97, 2000, or later?

    Remove the curly braces from the statement -> {}
    Code:
    sConn = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\mydatabase.mdb;User Id=admin;Password=;"
    Hi,
    I am using Access 2007

  6. #6
    Frenzied Member gibra's Avatar
    Join Date
    Oct 2009
    Location
    ITALY
    Posts
    1,396

    Re: Getting error while loading database connection

    Quote Originally Posted by madhusha View Post
    Hi,
    I am using Access 2007
    This isn't matter.

    Arnoutdv is right.
    Your code use a MDB database (2003 and previous), so you need use the JET provider.

    If you use a ACCDB database (2007 and later) then you must use the ACE provider:
    Code:
    "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & sDBPath
    If you distribute your application isn't a good idea to use ACCDB, because you need also to install the related drivers, while JET already present in any Windows version.

  7. #7
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,526

    Re: Getting error while loading database connection

    MS Access 2007 and later can create and use Jet 4.0 format MDBs as well as ACE 12.0 ACCDBs. The ACE Provider wraps the ACE Engine, which is an Office-private superset of the Jet 4.0 Engine that does not ship as part of any version of Windows.

    Even if you are using a compatible Provider you must still provide a valid connection string. The Data Source property value assigned within a connection string should be quoted if it contains characters that interfere with the heavy parsing done whenever the connection string value is assigned. You can use either quotation marks or apostrophes for this, and you should probably just use them every time.

    For example:

    Code:
    "Provider=Microsoft.ACE.OLEDB.12.0;Data Source='" & sDBPath & "'"

  8. #8
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,117

    Re: Getting error while loading database connection

    well no one said anything about the ACE Provider until Gibra brought it up in post #6...
    Since the user is using an MDB file, discussion about the ACCDB format is largely moot. It's like trying to diagnose a car problem by talking about motorcycles.
    Meanwhile the error is about not finding the database file ... given that he's using app.path right in the connection string... I'd question if it's even being formed right.
    Personally I'd dump the connectionstring to a string first... then check to see if this part of it: "Data Source =" & App.path & "\Vul_all_param_Project.mdb;" & _ is even coming out right.



    Ungh... the connection string is a red herring...

    dc.Database = App.path <-- what's this line for? What's "dc"? And why is its database being pointed to A PATH ???

    That's why it says "Could not find file '(unknown)'." ... the unknown was confusing me because the name of the database was already in the connectionstring.... now I think it's that line that's the issue, not the connectionstring.

    I'm guessing that dc is a datacontrol... but I don't see it being used anywhere in the code... so ....

    again:
    dc.Database = App.path <-- what's this line for? What's "dc"? And why is its database being pointed to A PATH ???


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

  9. #9
    PowerPoster
    Join Date
    Feb 2006
    Posts
    17,526

    Re: Getting error while loading database connection

    In post #3 he reported "Could not find installable ISAM" errors. This is commonly the result of a syntax error in the connection string that caused it to be parsed incorrectly.

    The "dc" might be one of the crusty old DAO objects. It looks like he is programming by copy/paste and has incompatible things intermixed, and probably doesn't even realize it.

  10. #10
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    31,117

    Re: Getting error while loading database connection

    So, what I think we have here is a verifiable quagmire of a thread where some of is just don't really know what is going on any more. :P

    So I think for the time being, I'm going to step out of the thread...


    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.