Question about Windows service to access Database

E

Eric Caron

Hi

I try to create a windows service to read content of my database at
each 60 minutes. I create my service, i put a timer and set it's
interval to 600000. This work good. My problem is that when I access
my database. It seem that I can't open my database. Hre's my code :

Dim myConnection As New OdbcConnection("DSN=pg_dem;USR=dba;PWD=tom")
Dim myQuery As String = "SELECT * FROM GL_ANNU WHERE no_gl='121110000'
Dim myCommand As New OdbcCommand(myQuery, myConnection)
Try
myConnection.Open()
'Dim myReader As OdbcDataReader
'myReader = myCommand.ExecuteReader()
'EventLog.WriteEntry("Lecture des données effectuées avec succès.")
Catch ex As Exception
'EventLog.WriteEntry("Erreur de base de données.")
'Finally
'EventLog.WriteEntry("Fermeture de la base de données.")
myConnection.Close()
End Try

What is my problem ?

Thanks
 
T

Tom Mertens

Is the DSN a User DSN or a System DSN? If it's a User DSN
it is only available to the currently logged on user.
Probably your service runs under different credentials
than the ones you are logged on with.

Resolution: create the DSN as a System DSN, or what I
prefer is to use DSN-less connection strings. A DSN-less
connection string specifies everything that's needed to be
configured in the connection string, such as DRIVER (ODBC
driver that is used) as well as all specific properties
for your ODBC driver. You can store the connection string
in a configuration file (perhaps encrypted for increased
security).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top