none
Failed to open the explicitly specified database [CLIENT: <local machine>] RRS feed

  • Question

  • Hi,

    I am trying below code in my WinForm application and it works perfectly but when I try the same code in Windows Service application I get this error in the EventLog:

    Login failed for user 'WORKGROUP\JASSIM-RAHMA$'. Reason: Failed to open the explicitly specified database 'maxmon'. [CLIENT: <local machine>]

    here is the code:


    using (SqlConnection sql_connection = new SqlConnection("Data Source=.\\MAXMON;Initial Catalog=maxmon;Integrated Security=True;"))
    {
        SqlCommand sql_command = new SqlCommand("sp_ping", sql_connection);
        sql_command.CommandType = CommandType.StoredProcedure;
        sql_command.Parameters.Add(new SqlParameter("@address_id", 9999));
        sql_command.Parameters.Add(new SqlParameter("@address_ip", address));
        sql_command.Parameters.Add(new SqlParameter("@address_name", hostEntry.HostName));
        sql_command.Parameters.Add(new SqlParameter("@roundtrip_time", reply.RoundtripTime));
        sql_command.Parameters.Add(new SqlParameter("@ttl", reply.Options.Ttl));
        sql_command.Parameters.Add(new SqlParameter("@dont_fragment", reply.Options.DontFragment));
        sql_command.Parameters.Add(new SqlParameter("@reply_length", reply.Buffer.Length));
    
        sql_command.Connection.Open();
        sql_command.ExecuteNonQuery();
    }
    
    
    
    

    Kindly help..

    Thanks,

    Jassim

    Thursday, July 18, 2019 12:32 AM

All replies

  • Hi Jassim Rahma, 

    Thank you for posting here.

    According to your problem, you probably don't have the right connection on the database.

    Please check the information about database connection.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Thursday, July 18, 2019 8:58 AM
    Moderator
  • but I am able to connect using the SAME connection exactly when I use it in a WinForm application
    Thursday, July 18, 2019 9:57 AM
  • Hi Jassim Rahma, 

    Thanks for your feedback.

    I have three questions to confirm with you:

    1.  Are two applications on the same machine?
    2.  Is the logged-in user the same with window’s user?
    3. Which line of the code throw the exception?

    We are waiting for your update.

    Best Regards,

    Xingyu Zhao


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Friday, July 19, 2019 9:28 AM
    Moderator