Below code is working fine when I am coding. I publish code in IIS and then connection is failing.
I know, When I am coding is taking my window login as credentials and In IIS it is taking AppPool Identity. How can I pass my windows login credentials to connectionstring?
Public Shared Function DbCollection(connectionString As String) As DatabaseCollection
Dim server As New Microsoft.SqlServer.Management.Smo.Server(connectionString)
Return server.Databases
End Function
Error:
Login failed for user 'Domain\Computername$'.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlClient.SqlException: Login failed for user
'Domain\Computername$'.
I’d add to @smoore’s post that a lot depends on the connection string and the configuration of sql server of allowing incoming connections. It might be set to only allow sql users, not windows ones which is looks like from the problem description. Can you give details of the connection string (anonymize/delete the user/password before pasting!) and what authentication mode is allowed by the sql server instance?