Could not find file '.mdb'

Davedps

New member
Joined
Apr 20, 2010
Messages
2
Programming Experience
1-3
Hi,

I'm trying to build a simple windows forms application and I'm stuck up with a problem.

Could not find file 'some\path\example.mdb'


here are my variables:

Private m_dbconn As OleDbConnection
Private m_dbReader As OleDbDataReader
Private m_dbCmd As OleDbCommand
Private m_dbConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + _ "Data Source=some\path\.mdb"
Private m_bLoaded As Boolean = False


Load form code:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
Dim bFirst As Boolean
Dim sDept As String
m_dbconn = New OleDbConnection(m_dbConnString)
m_dbCmd = m_dbconn.CreateCommand()
m_dbconn.Open()
bFirst = True
Dim cmdText As String = "SELECT DISTINCT LastName from Employees"
m_dbCmd.CommandText = cmdText
m_dbReader = m_dbCmd.ExecuteReader()
Do While (m_dbReader.Read())
sDept = CStr(m_dbReader.Item("LastName"))
If bFirst Then
cemp.Text = sDept
End If
cemp.Items.Add(sDept)
Loop
m_dbReader.Close()
m_bLoaded = True

End Sub


Any kind of help would be appreciated...

Dave
 
Obviously your application is not going to be able to find the file if it doesn't exist. Either you haven't deployed the database with the app or you've deployed it to a location that doesn't match the path in your connection string.

Generally speaking, you simply can't hard code a path. There are various reasons that that path might be invalid on a user's system. For connection strings you should take one of two approaches, or possibly both combined.

1. Store the connection string in the config file and have your app read it from there. Each user can then edit there own config file to include the appropriate path, plus any other properties that might be needed on their particular system.

2. Store the data file in the same folder as the EXE and then use the |DataDirectory| place-holder in the connection string, e.g.
VB.NET:
Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\database.mdb
 
Hi,

I'm sorry but I'm unable to understand what you have suggested me to do...

Can you please elaborate how to get rid of this error

my file is in c:/Times.mdb

Are you referring to Private m_dbConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + _ "Data Source=some\path\.mdb" when you are talking about connection string?Also,how do I eidt the config file to change the connection string settings and have my app read it from there?

When you are referring to same folder as the EXE,which EXE exactly are you referring to?

Excuse my knowledge and help me get rid out this problem...

Dave
 
Back
Top