none
Break debuging while debug windows service . Windows Service cant use statict class RRS feed

  • General discussion

  • Hi ,

      i am developming windows servervice for connect sql server and process records, at first i created one window application which has one class for run all functions, the class working great , then i copyed this class in windows service and i call run method this class. But i get object referans not set exception. then i tryed to debug windows service on my pc , but i realized when i try to use static class debugging stops even standart .net function for example Debug.Writeline("xxxxx"). i cant create sqlconnection in my static class, and i didnt get any exception message, but debugging is break all time. 

    is any one have any idea ? 
        

    Thursday, November 5, 2009 11:54 AM

All replies

  • Hi,
    Could you post some code snippet which brings you this trouble?

    Thanks,
    Eric
    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    Wednesday, November 11, 2009 10:10 AM
  •    when i call GetNewConnection() function throw exception couldnt create instance SqlConnection  


    public static SqlConnection GetNewConnection() {
                try {            
                    SqlConnection connection = new SqlConnection(connectionString);
                    connection.Open();
                    return connection;
                }
                catch (Exception ex) {
                   
                    System.Diagnostics.Debug.WriteLine(ex);
                    throw ex;
                }
            }
    Thursday, November 12, 2009 1:30 PM
  • Hi,
    Is there any inner exception? does the method GetNewConnection () get called for many times? whether the caller close the connection correctly?
    It will be helpful if you can post the method which invokes GetNewConnection ().

    Thanks,
    Eric


    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    Friday, November 13, 2009 8:49 AM
  • We are changing the issue type to “General Discussion” because you have not followed up with the necessary information. If you have more time to look at the issue and provide more information, please feel free to change the issue type back to “Question” by clicking "Change Type" at the top of the thread. If the issue is resolved, we will appreciate it if you can share the solution so that the answer can be found and used by other community members having similar questions.

    Thanks,
    Eric
    Please remember to mark helpful replies as answers and unmark them if they provide no help.
    Wednesday, November 18, 2009 6:16 AM
  • Connection is not close , i am sure because i open first connection on start code . i use all time same time at my projects , i don't understand why this project trow this exception, maybe i have problem my project settings , but i couldn't see any think .  



            public static SqlConnection GetNewConnection() {
                try {            
                    SqlConnection connection = new SqlConnection(connectionString);
                    connection.Open();
                    return connection;
                }
                catch (Exception ex) {
                   
                    System.Diagnostics.Debug.WriteLine(ex);
                    throw ex;
                }
            }




            public static DataTable GetBatchsByStatus(int statusId, int batchcount) {
                using (SqlConnection tmpConn = GetNewConnection()) {
                    try {
                        using (SqlCommand comm = new SqlCommand("pGetBatchsByStatus", tmpConn)) {
                            comm.CommandType = CommandType.StoredProcedure;

                            SqlParameter pBatchcount = comm.Parameters.Add("@TopQuantity", SqlDbType.Int);
                            pBatchcount.Value = batchcount;

                            SqlParameter pLockedBy = comm.Parameters.Add("@LockedBy", SqlDbType.Int);
                            pLockedBy.Value = userP.Id;

                            SqlParameter pStatus = comm.Parameters.Add("@Status", SqlDbType.Int);
                            pStatus.Value = statusId;

                            SqlDataAdapter da = new SqlDataAdapter(comm);
                            DataTable dt = new DataTable();
                            da.Fill(dt);
                            return dt;
                        }
                    }
                    catch (Exception ex) {
                        throw ex;
                    }
                    finally {
                        tmpConn.Close();
                    }
                }
            }
    Wednesday, November 18, 2009 7:47 AM
  • It is likely some permission issue - the account under which you run your service doesn't have sufficient permissions to access the SQL database/service. Or SQL is not started at the point you try to run your code.
    Find out what is the inner exception (as eryang already asked you) ... that will give you a lead.

    -Karel
    Monday, November 23, 2009 2:25 AM
    Moderator