views:

50

answers:

3

Hello when i run my application on server, the connection doesn't open --> my dataset is still closed

Dim strconnect As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + "rootPath" + "\" + "VSS_TESTDB.mdb" + "Persist Security Info=False"


Dim objConnection As New OleDbConnection(strconnect)

Dim sql As String = "SELECT VSS_Files.id, VSS_Files.filename,VSS_Files.dateOfCreation,VSSDirs.dir  FROM VSS_Files , VSSDirs Where VSS_Files.dir_id = VSSDirs.id;"


Dim cmd As New OleDbCommand(sql, objConnection)

Dim myDataReader As OleDbDataReader
        myDataReader = cmd.ExecuteReader()

what can i do?

greetings tyzak

A: 

This question is pretty vague, and it is difficult to properly diagnose from one line of code. Here are a couple of suggestions:

  1. You need to assign this connection string to a connection object.

  2. See http://www.connectionstrings.com/ for the full and proper form for connection strings.

NYSystemsAnalyst
+1  A: 

You need to create an OleDbConnection using an OleDbConnectionStringBuilder to connect to the database.

For example:

Dim builder As New OleDbConnectionStringBuilder
builder.Provider = "Microsoft.Jet.OLEDB.4.0"
builder.DataSource = Path.Combine(rootPath, "VSS_TESTDB.mdb")
builder.PersistSecurityInfo = False

Using connection As New OleDbConnection(builder.ToString())
Using command As New OleDbCommand("SELECT VSS_Files.id, VSS_Files.filename,VSS_Files.dateOfCreation,VSSDirs.dir  FROM VSS_Files, VSSDirs Where VSS_Files.dir_id = VSSDirs.id;", connection)
    connection.Open()
    Using reader As OleDbDataReader = command.ExecuteReader()
        'Do something
    End Using
End Using

EDIT: Your problem is probably that you put quotes around rootPath. The Data Source of your connection string is DataSource=rootPath\VSS_TESTDB.mdb. I assume that you actually want it to have the value of the rootPath variable.

Also, you need to open the connection.

Finally, you should close the connection and the DataReader using the Using statement.

See my updated example.

SLaks
hi, sorry i post some more code:Dim strconnect As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + "rootPath" + "\" + "VSS_TESTDB.mdb" + "Persist Security Info=False" Dim objConnection As New OleDbConnection(strconnect)Dim sql As String = "SELECT VSS_Files.id, VSS_Files.filename,VSS_Files.dateOfCreation,VSSDirs.dir FROM VSS_Files , VSSDirs Where VSS_Files.dir_id = VSSDirs.id;" Dim cmd As New OleDbCommand(sql, objConnection)Dim myDataReader As OleDbDataReader myDataReader = cmd.ExecuteReader()
Tyzak
A: 

hi, sorry i post some more code: Dim strconnect As String = "Provider=Microsoft.Jet.OLEDB.4.0;" + "Data Source=" + "rootPath" + "\" + "VSS_TESTDB.mdb" + "Persist Security Info=False"

Dim objConnection As New OleDbConnection(strconnect)

Dim sql As String = "SELECT VSS_Files.id, VSS_Files.filename,VSS_Files.dateOfCreation,VSSDirs.dir FROM VSS_Files , VSSDirs Where VSS_Files.dir_id = VSSDirs.id;"

Dim cmd As New OleDbCommand(sql, objConnection)

Dim myDataReader As OleDbDataReader myDataReader = cmd.ExecuteReader()

Tyzak
You should have edited your question.
SLaks