473,396 Members | 1,940 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

XML Web Service with Datareader Issues

Hello Experts.

I need your help, I am new to XML web service, and I have to complete one task.

Here is current situation.

1. I have web service running to recieve SOAP message from an external service and send message reciepts. This service Recieve XML as object and transforms into XML file and then imports that XML file into SQL Server database and then sends SOAP message reciept. I am not developer of that code, it is huge thousands of lines of code.

Now problem is when XML files recieved from multiple cleint at the same time, then importing of data process dies saying (Data reader already open).
************************************
This is my code behind ASMX file
Expand|Select|Wrap|Line Numbers
  1. Public
  2.  
  3. Function ProcessMessage(ByVal MESSAGE As wgsserver.MESSAGE) As <System.Xml.Serialization.XmlElementAttribute("MESSAGE", [Namespace]:="http://ws.abc.com/fieldservices/ext/message-receipt.xsd")> wgsserver.MessageType 
  4.  
  5. Dim returnMsg As wgsserver.MessageType 
  6.  
  7. Try 
  8.  
  9. 'log the request message 
  10.  
  11. Dim requestPath As String = Util.logRequestMessage(MESSAGE.Content.WorkOrder.Ref, MESSAGE) 
  12.  
  13. If requestPath Is Nothing Then 
  14. returnMsg = ResponseMessage.getMessageType(
  15.  
  16. False, "logRequestMessage Failed.") 
  17. Util.logResponseMessage(MESSAGE.Content.WorkOrder.Ref, returnMsg)
  18.  
  19.  
  20. Return returnMsg 
  21.  
  22. End If 
  23.  
  24. 'validate the request message against svreq.xsd 
  25.  
  26. Dim errorMessage As String = Util.validateRequestXML(requestPath) 
  27.  
  28. If errorMessage = "" Then 
  29.  
  30. 'Util.errorLog("No errors in validation") 
  31.  
  32. 'if there is no error 
  33.  
  34. If Util.ContainValidSenderAndRecipient(MESSAGE) Then 
  35.  
  36. 'if sender and recipient information are correct 
  37.  
  38. 'save the data into database. 
  39.  
  40. 'return success message-recipient 
  41.  
  42. Dim db As New DataBase 
  43. db.insert_table_MESSAGE(MESSAGE)
  44.  
  45.  
  46. If DataBase._errorMessage <> "" Then 
  47. returnMsg = ResponseMessage.getMessageType(
  48.  
  49. False, DataBase._errorMessage) 
  50. Util.logResponseMessage(MESSAGE.Content.WorkOrder.Ref, returnMsg)
  51.  
  52.  
  53. Return returnMsg 
  54.  
  55. End If 
  56. db.close()
  57.  
  58. returnMsg = ResponseMessage.getMessageType(
  59.  
  60. True, "") 
  61. Util.logResponseMessage(MESSAGE.Content.WorkOrder.Ref, returnMsg)
  62.  
  63.  
  64. Return returnMsg 
  65.  
  66. Else 
  67.  
  68. 'if not correct sender or recipient message 
  69.  
  70. 'create error log on server 
  71.  
  72. 'return failure message 
  73. Util.errorLog("Invalid Sender or Recipient")
  74.  
  75. returnMsg = ResponseMessage.getMessageType(
  76.  
  77. False, "Invalid Sender or Recipient") 
  78. Util.logResponseMessage(MESSAGE.Content.WorkOrder.Ref, returnMsg)
  79.  
  80.  
  81. Return returnMsg 
  82.  
  83. End If 
  84.  
  85. Else 
  86. Util.errorLog("xmlValidation:" & errorMessage)
  87.  
  88. returnMsg = ResponseMessage.getMessageType(
  89.  
  90. False, errorMessage) 
  91. Util.logResponseMessage(MESSAGE.Content.WorkOrder.Ref, returnMsg)
  92.  
  93.  
  94. Return returnMsg 
  95.  
  96. End If 
  97.  
  98. Catch ex As Exception 
  99. Util.errorLog("General: " & ex.Message & vbCrLf & ex.StackTrace)
  100.  
  101. returnMsg = ResponseMessage.getMessageType(
  102.  
  103. False, ex.Message) 
  104. Util.logResponseMessage(MESSAGE.Content.WorkOrder.Ref, returnMsg)
  105.  
  106.  
  107. Return returnMsg 
  108.  
  109. End Try 
  110.  
  111. End Function 
*********************

Now you could see one line which imports the db class (db.insert_table_MESSAGE(MESSAGE)) this actually a general VB class and perform importing process of data using MESSAGE object which is XML file. It works fine, if messages sent one by one, but in case of concurrent session it generates the following error message.

"There is already an open DataReader associated with this Connection which must be closed first."

****************************************
This is the code in Database Class
Expand|Select|Wrap|Line Numbers
  1. Public Function insert_table_MESSAGE(ByVal obj_MESSAGE As WGS.wgsserver.MESSAGE) As Integer
  2.  
  3.  
  4. If obj_MESSAGE Is Nothing Then 
  5.  
  6. Return -1 
  7.  
  8. End If 
  9.  
  10. Dim databaseString As String 
  11.  
  12. Dim reader As SqlDataReader 
  13.  
  14. Try 
  15.  
  16. Dim id_EnvelopeType As Integer = insert_table_EnvelopeType(obj_MESSAGE.Envelope) 
  17.  
  18. Dim id_Content As Integer = insert_table_Content(obj_MESSAGE.Content) 
  19. databaseString = "insert into table_MESSAGE (col_Envelope, col_Content, col_MsgType, col_Version) values (" & id_EnvelopeType & ", " & id_Content & ", '" & FSSConversion(obj_MESSAGE.MsgType) & "', '" & FSSConversion(obj_MESSAGE.Version) & "')"
  20.  
  21.  
  22. Dim command As New SqlCommand(databaseString) 
  23. command.Connection = conn
  24.  
  25. command.ExecuteNonQuery()
  26.  
  27. databaseString = "select id from table_MESSAGE where col_Envelope=" & id_EnvelopeType & " and col_Content=" & id_Content & " and col_MsgType='" & FSSConversion(obj_MESSAGE.MsgType) & "' and col_Version='" & FSSConversion(obj_MESSAGE.Version) & "'"
  28.  
  29.  
  30. Dim command2 As New SqlCommand(databaseString) 
  31. command2.Connection = conn
  32.  
  33. reader = command2.ExecuteReader()
  34.  
  35. reader.Read()
  36.  
  37.  
  38. Dim result As Integer = reader.GetInt32(0) 
  39. reader.Close()
  40.  
  41.  
  42. Return result 
  43.  
  44. Catch ex As Exception 
  45. _errorMessage = ex.Message
  46.  
  47.  
  48. If Not reader Is Nothing Then 
  49. reader.Close()
  50.  
  51.  
  52. End If 
  53. Util.errorLog("ERROR INSERT: " & ex.Message & vbCrLf & ex.StackTrace)
  54.  
  55.  
  56. End Try 
  57.  
  58. Return -1 
  59.  
  60. End Function 
*********************************************


I need your expert advice. I need to make that Web Service Working for Multiple Client concurrently.
Any help please...


Thanks in advance.
Apr 11 '07 #1
4 1765
dorinbogdan
839 Expert 512MB
Welcome to TheScripts TSDN...

Since the problem is related to ADO.Net I will move this thread to .Net forum.

Dorin.
Apr 11 '07 #2
dorinbogdan
839 Expert 512MB
One suggestion: check that the conn variable to not be defined as Shared (static).
Apr 11 '07 #3
Sorry about that.

I checked that and it is declared with in class as
"Private Shared conn As SqlConnection"

Is that going to be an issue?

Thanks for your help.
Apr 11 '07 #4
dorinbogdan
839 Expert 512MB
Just remove the Shared modifier, it should have no negative effect, since it's a private variable.
Then try few tests to make sure that it's working as desired.

Dorin.
Apr 12 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Dave O | last post by:
Is it possible to return a SQLdatareader from a web service?
2
by: Sean | last post by:
Hello all, I may just not be searching for the right thing, but I've been looking for a way to dynamically create controls (and name them) in my code so that I can create only the controls I...
2
by: Andrei Pociu | last post by:
In a typical ASP .NET Web Application (website), I'm currently using a class where I declare some public static objects. For example there's the place where I initialize the SqlConnection. Also...
2
by: Sumaira Ahmad | last post by:
Hi All My Web Service is returning a DataSet. I realized that we cannot return a DataReader.. Normally we can use a DataReader( when not using Web services) and access it as below to assign...
14
by: Bihn | last post by:
I was reading about datareader which is said to be slimmer & faster then dataset. Since the datareader have to go fetching the dat from the database every time it need it, the data it gets then...
8
by: David Perona | last post by:
Hi all, I have a web service that connects to a SQL Server database and return an sqlDataReader Object. When launch the web service in the web browser, this exception is thrown: "Object...
7
by: Varangian | last post by:
Hi all, the question I want to ask if the conversion of a DataReader to a Table looping through the DataReader is better than using the Fill Method of the DataAdapter... I'm asking because...
7
by: Diffident | last post by:
Hello All, I would like to use DataReader based accessing in my Data Access Layer (DAL). What is considered to be a best practice while returning from a DAL method that executes a query and...
5
by: TompIfe | last post by:
Hi, I have a web service that reads data from an Access database using datareader and place the data in an array that the web method returns. Now, I want to make the web service also to return an...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.