Search code examples
c#.netado.netremoting

SqlConnection via Remoting


I develop a wpf host app with plugins and want to share them SqlConnection, but when i try to pass object of SqlConnection via Remoting, i get an error:

remoting cannot find field 'objectid' on type 'system.data.sqlclient.sqlconnection'

Google and SO didn't help me and the only topic i found is with broken links :(

Can i somehow pass SqlConnection? The trouble is that i already have ado.net-based application and i don't have a possibility to rewrite them. And on the other hand, i need to provide different plugins access to same connection because they can interop via temporary tables.

Exception info:

(last error: Remoting cannot find field 'ObjectID' on type 'System.Data.SqlClient.SqlConnection'.). 
StackTrace:
Server stack trace: 
   at System.Object.GetFieldInfo(String typeName, String fieldName)
   at System.Object.FieldGetter(String typeName, String fieldName, Object& val)
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.SyncProcessMessage(IMessage msg)

Exception rethrown at [0]: 
   at System.Runtime.Remoting.Proxies.RealProxy.HandleReturnMessage(IMessage reqMsg, IMessage retMsg)
   at System.Runtime.Remoting.Proxies.RealProxy.PrivateInvoke(MessageData& msgData, Int32 type)
   at System.Object.FieldGetter(String typeName, String fieldName, Object& val)
   at System.Data.SqlClient.SqlCommand.set_Connection(SqlConnection value)
   at LSSample.SampleUserControl.ExecuteSqlLocal() in c:\Users\voskresenskiy\Documents\Visual Studio 2013\Projects\UIContainer\WpfHost\LSSample\SampleUserControl.xaml.cs:line

I'll be gratefull for any help


Solution

  • From the exception call stack and using Reflector I can see that SqlCommand.set_Connection is trying to access SqlConnection.ObjectID. SqlConnection.ObjectID is marked as internal, only public members are available via remoting.

    Doesn't SqlConnection use pooling to minimize the number of database connections? SQL Server Connection Pooling

    Could you have one process that talks to the database, then all of the other processes will request data from it, just by passing it the query string?