I wrote a windows service that takes data from a local database and performs a function. To connect to the database I wrote the following code

```
SqlConnection connstring1;
            string conn1 = ConfigurationManager.ConnectionStrings["nameOfConnectionString"].ConnectionString.ToString();
            connstring1 = new SqlConnection(conn1);
            connstring1.Open();
            string cmd = "Select [OrderId], [VendorId], [txtPaymentMethod] , [txtPaymentStatus], [Updated_On] FROM [Postmate_ Shopping].[dbo].[tbl_Order_Master]  WHERE [txtPaymentMethod] = 'online' AND [txtPaymentStatus]= 'pending'";
            DataTable dt = new DataTable();
            DataSet ds = new DataSet();
            SqlDataAdapter da1 = new SqlDataAdapter(cmd, connstring1);
            da1.Fill(ds);
            da1.Dispose();
            connstring1.Close();

```

The code before da1.Fill(ds); is working and service gets installed but when da1.Fill(ds); is included in the code, service does not start.
I tried the same code in a web application and It was working fine.
This is what I get when da1.Fill(ds); is included:

***The "ScheduledService" service on Local Computer started and then stopped.Some services stop automatically if they are not in use by other services or programs.***

To check if the service is working properly I removed the above code and replaced it with this code:

```
FileStream fs = new FileStream(@"d:\ScheduledService.txt",
FileMode.OpenOrCreate, FileAccess.Write);
//set up a streamwriter for adding text
StreamWriter sw = new StreamWriter(fs);

//find the end of the underlying filestream
sw.BaseStream.Seek(0, SeekOrigin.End);

//add the text
sw.WriteLine(content);
//add the text to the underlying filestream
sw.Flush();
//close the writer
sw.Close();

```

the service worked fine.
I tried searching for the problem but no relevant solution could be found.
Please help. Thanks in advance. 

Ask for clarity if needed.

EDIT:Any thoughts on using datareader?