Question Locked

Is it possible to open a connection inside a windows service?

0 helpful
2 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.

Good day TR community! I created a windows service (vb.net) which reads the content of a DBF file table and import it to a MySQL table. The problem occurs at the line where I'm trying to open the connection between DBF and vb.net. Here's the code I've been using:

Dim conn As OdbcConnection = Nothing
Dim comm As OdbcCommand = Nothing
Dim connectionString As String
Dim sql As String

connectionString = "DSN=dbfconn"
sql = SELECT * FROM TableName.DBF

conn = New OdbcConnection(connectionString)

conn.Open() --THIS IS WHERE THE PROBLEM OCCURS

comm = New OdbcCommand(sql, conn)
dr = comm.ExecuteReader()

InsertToMySQL --SUB ROUTINE FOR INSERTING dr TO MYSQL TABLE

conn.Close()
dr.Close()
comm.Dispose()
conn.Dispose()

These line of codes runs smoothly in a window based application (vb.net), but having problems when used in a windows service application (vb.net). I began to wonder if it's really possible to open a connection between DBF and VB.net inside a windows service.

Any help is highly appreciated. Thank you!

2 replies

by tony hopkinson

Connect to it directly but why are you using ODBC?

Get hold of MySQLConnection, gives you native connectivity akin to that for sql server.

HtHs

This discussion is closed to new replies.