2

Im trying to access an SQL database from a custom TimerJob, but it fails. Without hitting the Exception, it just stops. I got the exact line where it get stuck:

SqlDataReader sqlReader = sqlQuery.ExecuteReader();

whats wrong with that line? Can a Custom TimerJob access SQL Server?

3 Answers 3

1

The short answer is yes, a custom timer job can access sql server. However in order to work out what your problem is, you'll probably need to provide us with more information. For example you may have an issue with your connection string, permissions on the database you are trying to access etc.

0

Make sure the user account running the Timer Service has access to SQL server and the objects you are calling from your timer job. You can find this under Services in Administrative Tools.

Try running the sql profiler over the DB to see if a connection is established and what (if any) queries were executed.

0

thanks for answering, I found something interesting... You can connect to SQL server, BUT, you cant use (for some weird, unknown reason) this access:

SqlDataReader sqlReader = sqlQuery.ExecuteReader();

Instead of using that, you need to use:

SqlDataAdapter da = new SqlDataAdapter(sqlQuery.CommandText, connection);

If someone knows the reason you cant use the first statement, please comment. For everyone else having the same issue, try the 2nd statement.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.