Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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