DBcontext Webservice中的对象,由线程应用程序使用 [英] DBcontext Object within webservice and consumed by threaded application

查看:66
本文介绍了DBcontext Webservice中的对象,由线程应用程序使用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我创建了一个Web服务并托管在localhost中,它通过单个静态LINQ DBcontext对象进行一些数据库操作。而这个网络服务被托管在同一台机器上的另一个Windows服务所使用,这个机器正在使用,所以多个线程同时点击我的web服务,每个线程都很好地执行他们的任务但是有时候我们收到了以下类型的错误。



对象引用未设置为对象的实例。



StackTrace:在System.Data.Linq.SqlClient .SqlConnectionManager.BootUser(IConnectionUser用户)

在System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser用户)

在System.Data.Linq.SqlClient.SqlProvider .Execute(表达式查询,QueryInfo queryInfo,IObjectReaderFactory工厂,Object [] parentArgs,Object [] userArgs,ICompiledSubQuery [] subQueries,Object lastResult)

at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll (表达式查询,QueryInfo [] queryInfos,IObjectReaderFactory factory,Object [] userArguments,ICompiledSubQuery [] subQueries)

at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(表达式查询)

在System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider。在System.Linq.Queryable.Count [TSource](IQueryable`1 source)执行[S](表达式表达式)



在SMS.BLL.Subscriber.GetSubscriberByID( Guid p_subscriberID)




=========================== ==========================



指数超出界限数组。

StackTrace:在System.Collections.Generic.List`1.RemoveAt(Int32索引)

在System.Data.Linq.SqlClient.SqlConnectionManager.BootUser (IConnectionUser用户)

在System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser用户)

在System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query,QueryInfo queryInfo,IObjectReaderFactory factory,Object [] parentArgs,Object [] userArgs,ICompiledSubQuery [] subQueries,Obje ct lastResult)

在System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query,QueryInfo [] queryInfos,IObjectReaderFactory factory,Object [] userArguments,ICompiledSubQuery [] subQueries)

at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)

at SMS.BLL.SMSDataClassesDataContext.SMS_INSERTMT(String sUBSCRIBERID,XElement mESSAGEXML)

在SMS.BLL.Subscriber.SaveMTMessages(Guid SubscriberID,Byte [] smsInfoCompressed,String EncodingName)







有人可以帮帮我吗?



谢谢

Rohit

Hi,

I have created a web-service and hosted in localhost which is doing some database operation through single static LINQ DBcontext Object. And this web-service is consumed by another windows service hosted in same machine which is using tread so multiple thread is hitting my webservice simultaneously and every thread perform their task nicely but SOMETIMES we are receiving following kind of errors.

Object reference not set to an instance of an object.

StackTrace: at System.Data.Linq.SqlClient.SqlConnectionManager.BootUser(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)
at SMS.BLL.Subscriber.GetSubscriberByID(Guid p_subscriberID)


=====================================================

Index was outside the bounds of the array.
StackTrace: at System.Collections.Generic.List`1.RemoveAt(Int32 index)
at System.Data.Linq.SqlClient.SqlConnectionManager.BootUser(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlConnectionManager.UseConnection(IConnectionUser user)
at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)
at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)
at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)
at SMS.BLL.SMSDataClassesDataContext.SMS_INSERTMT(String sUBSCRIBERID, XElement mESSAGEXML)
at SMS.BLL.Subscriber.SaveMTMessages(Guid SubscriberID, Byte[] smsInfoCompressed, String EncodingName)



Can anybody help me please?

Thanks
Rohit

推荐答案

没有看到代码就会得到一般答案。



但是尝试在每个请求上处理DataContext。



只需添加解决类似问题的链接问题。另请阅读帖子中与答案相关的评论。



http://stackoverflow.com/questions/6653874/strange-linq-exception [ ^ ]
Without seeing the code would be bit of a generic answer.

But try to Dispose the DataContext over each request.

Just adding a link which solves the similar issue. Also read the Comments related to the Answer in the post.

http://stackoverflow.com/questions/6653874/strange-linq-exception[^]


这篇关于DBcontext Webservice中的对象,由线程应用程序使用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆