I'm trying to run a stored procedure that is linked to two servers. The stored procedure runs perfectly from SSMS but it will not run from my VB.Net code. If I remove the reference to the linked server, it runs correctly. However, I need the linked server reference in the stored procedure.
The 4 part reference is set up correctly. The linked server connection is set up correctly. We seem to think it's the data connection in VB but we've tried everything but we keep getting a login-mapping error.
The connection string is below. We basically pull from an XML file where our IP addresses and login information are stored. That's the "/Settins/Catalogs..." variable.
Public Shared Function GetConnString(ByVal sConn As String) As SqlClient.SqlConnectionStringBuilder
_dbServer = GetBakerGlobalSettingsValue("/Settings/Catalogs/SNL/DataSource")
_dbLoginName = GetBakerGlobalSettingsValue("/Settings/Catalogs/SNL/UserId")
_dbLoginPassword = GetBakerGlobalSettingsValue("/Settings/Catalogs/SNL/Password")
_InitialCatalog = "SNL"
Dim sbConnString As New SqlClient.SqlConnectionStringBuilder
sbConnString.DataSource = _dbServer
sbConnString.InitialCatalog = _InitialCatalog
sbConnString.UserID = _dbLoginName
sbConnString.Password = _dbLoginPassword
sbConnString.IntegratedSecurity = False
Return (sbConnString)
End Function
Dim aDate As Date = "2010-06-30"
Using sqlCommand As New SqlCommand("VerifyPortfolioFedIds '" & aDate & "'", connPort)
sqlCommand.CommandTimeout = 300
Dim da As SqlDataAdapter = New SqlDataAdapter() With {.SelectCommand = sqlCommand}
Dim dt As DataTable = New DataTable
da.Fill(dt)
MsgBox(dt.Rows.Count.ToString)
End Using