-
Mar 8th, 2017, 10:17 AM
#1
Thread Starter
New Member
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
-
Mar 8th, 2017, 10:58 AM
#2
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/
-
Mar 8th, 2017, 12:12 PM
#3
Thread Starter
New Member
Re: Getting error while loading database connection
Originally Posted by Arnoutdv
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="
-
Mar 9th, 2017, 02:14 AM
#4
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=;"
-
Mar 11th, 2017, 01:13 AM
#5
Thread Starter
New Member
Re: Getting error while loading database connection
Originally Posted by Arnoutdv
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
-
Mar 11th, 2017, 08:35 AM
#6
Re: Getting error while loading database connection
Originally Posted by madhusha
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.
Last edited by gibra; Mar 11th, 2017 at 08:41 AM.
-
Mar 12th, 2017, 11:38 AM
#7
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 & "'"
-
Mar 13th, 2017, 09:27 AM
#8
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
-
Mar 13th, 2017, 11:19 AM
#9
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.
-
Mar 13th, 2017, 11:59 AM
#10
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
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|