Categories: MSDN / DotNet / Java / Scripts / Linux / PHP Ask - La ask - La Answer

.NET service

Ok im going crazy trying to get my service to run a SQL Stored Procedure with a parameter. Here is the code.

Dim conn As New SqlConnection("Data Source=Server;Initial Catalog=Mytable;Integrated Security=True")
Dim cmd As New SqlCommand
Dim dr As SqlDataReader
conn.Open()
cmd.Connection = conn
cmd.CommandType = Data.CommandType.StoredProcedure
cmd.CommandText = "Citation_Pull"
cmd.Parameters.Add("@CitationNumber", Data.SqlDbType.VarChar).Value = e.Name.ToString
dr = cmd.ExecuteReader

What happens is the service sees a new file in a folder, pulls the name and sends that name onto the SP to run. And this is kicking my butt, ive been on this quite a few days. And i cant get it to run..
[822 byte] By [BrownRJ] at [2007-11-11 8:43:41]
# 1 Re: .NET service
With no replies. Does this mean it "should" work? Im at a loss.
BrownRJ at 2007-11-11 21:47:08 >
# 2 Re: .NET service
Um, how can people help if you haven't told them how it fails?
kentcb at 2007-11-11 21:48:08 >
# 3 Re: .NET service
Um, how can people help if you haven't told them how it fails?

Hmm Fails as in it does not work. It does not connect, does not run the Stored procedure, does not insert any of the information into the table. I made the stupid assumption that if i had the connection string wrong somebody would tell me. Does any of that code look wrong to you?

But at this point I dont think its a coding issue.
BrownRJ at 2007-11-11 21:49:06 >
# 4 Re: .NET service
In your connection string you are specifying 'Integrated Security'. If your service is running under the Local System Account or Network Service account you will probably NOT connect to SQL Server with those credentials.

Try changing the connection string to include a named SQL Server user and password and see if that works. The syntax is:

User ID=username;Password=userpassword;

Alternately, you can set the service up to run under a named user account that has connectivity to SQL Server.

Hope this helps... :cool:
shstubbs at 2007-11-11 21:50:06 >
# 5 Re: .NET service
I think it may have bee then I didnt have the server name as (local) , I had it as local. But it seems to be working, thanks for your reply. :)
BrownRJ at 2007-11-11 21:51:11 >