473,662 Members | 2,454 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

XML Web Service with Datareader Issues

2 New Member
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_tabl e_MESSAGE(MESSA GE)) 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 1786
dorinbogdan
839 Recognized Expert Contributor
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 Recognized Expert Contributor
One suggestion: check that the conn variable to not be defined as Shared (static).
Apr 11 '07 #3
rikleo2001
2 New Member
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 Recognized Expert Contributor
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
8655
by: Dave O | last post by:
Is it possible to return a SQLdatareader from a web service?
2
332
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 need at run time. For example, I'm writing a filewatcher service that will eventually write back to a database, but I may need the service to watch multiple directories (thus, multiple FileSystemWatcher components). The rub is this...how do I...
2
1571
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 there's the place where I declare one public static DataReader, but I'm not sure this is the best way to do it. I use that DataReader in all the webforms and user controls, whenever I have to read data from the db. So, should I do it this way or...
2
1245
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 values of columns of returned rows to Labels in the client aplication such as: while (dtrJobDetails.Read()) { l_shortjobdesc.Text = dtrJobDetails.ToString();
14
2233
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 should be up to date. However, both the IbuySpy and Duwamish samples and most, if not all, the shopping cart sample codes I've seen use dataset to implement the opration for ecommerce sites. So is the trip that the datareader need to go fetch the...
8
10662
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 Reference not established" from System.NullReferenceException. If I change the web service to return a integer value, its run ok. I'm Importing the System.Data.SqlClient namespace. What's the problem?
7
3391
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 internally the DataAdapter uses the DataReader... so whats the deal of writing a method that converts a DataReader into a DataTable ? Thanks!
7
2903
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 returns N rows. DataReader object? Collection object? DataTable object? Returning a DataReader object is not a good practice...right? Thnks for all your suggestions!!
5
5167
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 xml file with the data. How do I best proceed? Best regards, Tom
0
8432
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8343
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8856
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8762
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
8633
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
7365
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6185
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4347
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
2762
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system

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.