I have been trying to get SQL server to link to MAS for the last week. Meaning I am trying to create a linked server to MAS or create an extended stored procedure to read MAS data and return it to SQL server.
So far I have had success reading MAS data from a regular application, but when I attempt to use an extended stored procedure I get all kinds of varying results. Nothing works consistently and its becoming very frustating. I dont know if its the way that SQL server manages connections internally or what but the same exact code in my VB.NET Windows Application works fine, but when its executed by SQL Server it connects sometimes (but never returns data correctly) and sometimes I get an "Invalid handle" error like this:
System.Data.Odbc.OdbcException
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle)
at System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.Odbc.OdbcConnection.Open()
at ImportMASCompany.ImportCompany(String CompanyCode)
and here is my VB code that SQL calls through an extended stored procedure:
Public Shared Function ImportAllCompanies() As Integer
Dim conn As SqlConnection
Try
conn = New SqlConnection("Context Connection = True")
conn.Open()
Dim sqlReader As SqlDataReader
Dim cmd As SqlCommand
cmd = conn.CreateCommand
cmd.CommandText = "SELECT * FROM sysobjects"
sqlReader = cmd.ExecuteReader()
SqlContext.Pipe.Send(sqlReader)
Catch ex As Exception
SqlContext.Pipe.Send(ex.ToString())
Finally
SqlContext.Pipe.Send("Successful")
End Try
End Function
Has anyone ever tried this or gotten a MAS linked server setup right in SQL Server? If so, please help. Im about ready to quit!
So far I have had success reading MAS data from a regular application, but when I attempt to use an extended stored procedure I get all kinds of varying results. Nothing works consistently and its becoming very frustating. I dont know if its the way that SQL server manages connections internally or what but the same exact code in my VB.NET Windows Application works fine, but when its executed by SQL Server it connects sometimes (but never returns data correctly) and sometimes I get an "Invalid handle" error like this:
System.Data.Odbc.OdbcException
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcConnectionHandle..ctor(OdbcConnection connection, OdbcConnectionString constr, OdbcEnvironmentHandle environmentHandle)
at System.Data.Odbc.OdbcConnectionFactory.CreateConnection(DbConnectionOptions options, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningObject)
at System.Data.ProviderBase.DbConnectionFactory.CreateNonPooledConnection(DbConnection owningConnection, DbConnectionPoolGroup poolGroup)
at System.Data.ProviderBase.DbConnectionFactory.GetConnection(DbConnection owningConnection)
at System.Data.ProviderBase.DbConnectionClosed.OpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory)
at System.Data.Odbc.OdbcConnection.Open()
at ImportMASCompany.ImportCompany(String CompanyCode)
and here is my VB code that SQL calls through an extended stored procedure:
Public Shared Function ImportAllCompanies() As Integer
Dim conn As SqlConnection
Try
conn = New SqlConnection("Context Connection = True")
conn.Open()
Dim sqlReader As SqlDataReader
Dim cmd As SqlCommand
cmd = conn.CreateCommand
cmd.CommandText = "SELECT * FROM sysobjects"
sqlReader = cmd.ExecuteReader()
SqlContext.Pipe.Send(sqlReader)
Catch ex As Exception
SqlContext.Pipe.Send(ex.ToString())
Finally
SqlContext.Pipe.Send("Successful")
End Try
End Function
Has anyone ever tried this or gotten a MAS linked server setup right in SQL Server? If so, please help. Im about ready to quit!