none
DatabaseMail.exe stops immediately after running, shows below log if it is ran as an administrator SQL2017 RRS feed

  • Question

  • Hi, I have an SQL2017 server installed in my machine and I have admin access to it. I've configured databasemail in my instance.

    Ensured:
    >> Remote login is enabled in the database
    >> .NET 3.5 is installed on the server
    >> We are able to send emails using the same SMTP server through powershell

    Observation:
    >> "exec msdb..sysmail_help_status_sp" gives an output of "STARTED"
    >> test emails are always getting queued and never processed
    >> even if we delete unsent items, "exec msdb..sysmail_help_queue_sp" gives 44 as length for mail column and this keeps increasing the more test mails we send. State is always "INACTIVE"
    >> Double clicking databasemail.exe starts the process and stops immediately. Starting it from command prompt gives the error:The type initializer for 'Microsoft.SqlServer.Management.SqlIMail.Server.Common.Logger' threw an exception.
    >> Running databasemail.exe as an administrator logs an event in the applications event log as follow

    Log Name:      Application
    Source:        DatabaseMail
    Date:          9/24/2020 2:32:44 PM
    Event ID:      0
    Task Category: None
    Level:         Error
    Keywords:      Classic
    User:          N/A
    Computer:      <<COMPUTERNAME>>
    Description:


    1) Exception Information
    ===================
    Exception Type: Microsoft.SqlServer.Management.SqlIMail.Server.Common.BaseException
    Message: There was an error on the connection. Reason: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server), connection parameters: Server Name: ., Database Name: msdb
    Data: System.Collections.ListDictionaryInternal
    TargetSite: Void OpenConnection(Microsoft.SqlServer.Management.Common.SqlConnectionInfo)
    HelpLink: NULL
    Source: DatabaseMailEngine
    HResult: -2146232832

    StackTrace Information
    ===================
       at Microsoft.SqlServer.Management.SqlIMail.Server.DataAccess.ConnectionManager.OpenConnection(SqlConnectionInfo connectionInfo)
       at Microsoft.SqlServer.Management.SqlIMail.IMailProcess.QueueItemProcesser.ProcessQueueItems(String dbName, String dbServerName, Int32 lifetimeMinimumSec, LogLevel loggingLevel, Byte[] encryptionKey, Int32 connectionTimeout)

    2) Exception Information
    ===================
    Exception Type: System.Data.SqlClient.SqlException
    Errors: System.Data.SqlClient.SqlErrorCollection
    ClientConnectionId: 00000000-0000-0000-0000-000000000000
    Class: 20
    LineNumber: 0
    Number: 2
    Procedure: NULL
    Server: 
    State: 0
    Source: .Net SqlClient Data Provider
    ErrorCode: -2146232060
    Message: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)
    Data: System.Collections.ListDictionaryInternal
    TargetSite: Boolean TryGetConnection(System.Data.Common.DbConnection, UInt32, Boolean, Boolean, System.Data.Common.DbConnectionOptions, System.Data.ProviderBase.DbConnectionInternal ByRef)
    HelpLink: NULL
    HResult: -2146232060

    StackTrace Information
    ===================
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
       at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       at System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       at System.Data.SqlClient.SqlConnection.Open()
       at Microsoft.SqlServer.Management.SqlIMail.Server.DataAccess.ConnectionManager.OpenConnection(SqlConnectionInfo connectionInfo)

    3) Exception Information
    ===================
    Exception Type: System.ComponentModel.Win32Exception
    NativeErrorCode: 2
    ErrorCode: -2147467259
    Message: The system cannot find the file specified
    Data: System.Collections.ListDictionaryInternal
    TargetSite: NULL
    HelpLink: NULL
    Source: NULL
    HResult: -2147467259

    I've tried everything that I can think of:

    >> ensured I have access privileges to databasemail.exe 
    >> restarted SQL services several times
    >> recreated profiles and accounts (with the same SMTP server)
    >> Enabled NamedPipes
    >> Remote login to the database instance is possible

    Any ideas or solutions are highly appreciated!!! This is causing a pain in our environment and we need to enable databasemail feature. 

    History
    >> The database was earlier hosted under SQL 2008, and it is migrated to SQL 2017 now. the DBs work fine. 
    >> Ports we are using "AND CANNOT BE CHANGED" are different from default ports

    Friday, September 25, 2020 7:14 AM

All replies