Valid SELECT statement resulting in empty DataSet

Published Mar 23 2019 04:10 AM 53 Views
Microsoft
First published on MSDN on Oct 10, 2005

When using a Visual Studio 2005 application to retrieve a SELECT statement resultset through SQL 2005 native web services, the resultset is de-serialized from the wire format into a DataSet object. It is possible that even though the resultset is completely valid (ie. has columns and rows), the DataSet object is still empty. This scenario occurs when the web method called is not configured to return the XSD schema for the resultset.
For example, the endpoint was configured as:

CREATE ENDPOINT sql_endpoint
STATE = STARTED
AS HTTP(
PATH = '/sql',
AUTHENTICATION = (INTEGRATED ),
PORTS = ( CLEAR ),
SITE = 'SERVER'
)
FOR SOAP (
WEBMETHOD 'foobar'
(name='master.dbo.sp_foobar'),
WSDL = DEFAULT,
SCHEMA=NONE,
DATABASE = 'master',
NAMESPACE = 'http://tempUri.org/'
);
Or
CREATE ENDPOINT sql_endpoint
STATE = STARTED
AS HTTP(
PATH = '/sql',
AUTHENTICATION = (INTEGRATED ),
PORTS = ( CLEAR ),
SITE = 'SERVER'
)
FOR SOAP (
WEBMETHOD 'foobar'
(name='master.dbo.sp_foobar', SCHEMA=NONE),
WSDL = DEFAULT,
DATABASE = 'master',
NAMESPACE = 'http://tempUri.org/'
);

The reason behind the empty DataSet is because when the XSD schema for the resultset is not returned in the response, the DataSet object has no mechanism to determine what the table structure is (ie. how many columns are there and what the data type is for each of the columns).


This problem can be resolved by either updating the webmethod (recommended) keyword "SCHEMA" to "STANDARD" or, updating the "FOR SOAP" section keyword "SCHEMA" to "STANDARD".

ALTER ENDPOINT sql_endpoint
FOR SOAP
(
ALTER WEBMETHOD 'foobar' (name='myDatabase.dbo.sp_foobar', SCHEMA=STANDARD)
);
or
ALTER ENDPOINT sql_endpoint
FOR SOAP
(
SCHEMA=STANDARD
);

Please note that by default the SCHEMA keyword within the WEBMETHOD section is set to "DEFAULT", which means it defers to the SCHEMA setting for the SOAP endpoint. The default setting for the SOAP endpoint when the SCHEMA keyword is not specified within the FOR SOAP section is STANDARD. So, the scenario where this problem occurs would exist only if some one explicitly specified "NONE" for the SCHEMA keyword.


Please refer to CREATE ENDPOINT and ALTER ENDPOINT in Books Online for complete details.


Jimmy Wu, SQL Server Protocols
Disclaimer: This posting is provided "AS IS" with no warranties, and confers no rights

%3CLINGO-SUB%20id%3D%22lingo-sub-383026%22%20slang%3D%22en-US%22%3EValid%20SELECT%20statement%20resulting%20in%20empty%20DataSet%3C%2FLINGO-SUB%3E%3CLINGO-BODY%20id%3D%22lingo-body-383026%22%20slang%3D%22en-US%22%3E%0A%20%26lt%3Bmeta%20http-equiv%3D%22Content-Type%22%20content%3D%22text%2Fhtml%3B%20charset%3DUTF-8%22%20%2F%26gt%3B%3CSTRONG%3E%20First%20published%20on%20MSDN%20on%20Oct%2010%2C%202005%20%3C%2FSTRONG%3E%20%3CBR%20%2F%3E%3CP%3EWhen%20using%20a%20Visual%20Studio%202005%20application%20to%20retrieve%20a%20SELECT%20statement%20resultset%20through%20SQL%202005%20native%20web%20services%2C%20the%20resultset%20is%20de-serialized%20from%20the%20wire%20format%20into%20a%20DataSet%20object.%20It%20is%20possible%20that%20even%20though%20the%20resultset%20is%20completely%20valid%20(ie.%20has%20columns%20and%20rows)%2C%20the%20DataSet%20object%20is%20still%20empty.%20This%20scenario%20occurs%20when%20the%20web%20method%20called%20is%20not%20configured%20to%20return%20the%20XSD%20schema%20for%20the%20resultset.%20%3CBR%20%2F%3E%20For%20example%2C%20the%20endpoint%20was%20configured%20as%3A%3C%2FP%3ECREATE%20ENDPOINT%20sql_endpoint%20%3CBR%20%2F%3E%20STATE%20%3D%20STARTED%20%3CBR%20%2F%3E%20AS%20HTTP(%20%3CBR%20%2F%3E%20PATH%20%3D%20'%2Fsql'%2C%20%3CBR%20%2F%3E%20AUTHENTICATION%20%3D%20(INTEGRATED%20)%2C%20%3CBR%20%2F%3E%20PORTS%20%3D%20(%20CLEAR%20)%2C%20%3CBR%20%2F%3E%20SITE%20%3D%20'SERVER'%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20FOR%20SOAP%20(%20%3CBR%20%2F%3E%20WEBMETHOD%20'foobar'%20%3CBR%20%2F%3E%20(name%3D'master.dbo.sp_foobar')%2C%20%3CBR%20%2F%3E%20WSDL%20%3D%20DEFAULT%2C%20%3CBR%20%2F%3E%20SCHEMA%3DNONE%2C%20%3CBR%20%2F%3E%20DATABASE%20%3D%20'master'%2C%20%3CBR%20%2F%3E%20NAMESPACE%20%3D%20'%3CA%20href%3D%22http%3A%2F%2FtempUri.org%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2FtempUri.org%2F%3C%2FA%3E'%20%3CBR%20%2F%3E%20)%3B%20%3CBR%20%2F%3E%20Or%20%3CBR%20%2F%3E%20CREATE%20ENDPOINT%20sql_endpoint%20%3CBR%20%2F%3E%20STATE%20%3D%20STARTED%20%3CBR%20%2F%3E%20AS%20HTTP(%20%3CBR%20%2F%3E%20PATH%20%3D%20'%2Fsql'%2C%20%3CBR%20%2F%3E%20AUTHENTICATION%20%3D%20(INTEGRATED%20)%2C%20%3CBR%20%2F%3E%20PORTS%20%3D%20(%20CLEAR%20)%2C%20%3CBR%20%2F%3E%20SITE%20%3D%20'SERVER'%20%3CBR%20%2F%3E%20)%20%3CBR%20%2F%3E%20FOR%20SOAP%20(%20%3CBR%20%2F%3E%20WEBMETHOD%20'foobar'%20%3CBR%20%2F%3E%20(name%3D'master.dbo.sp_foobar'%2C%20SCHEMA%3DNONE)%2C%20%3CBR%20%2F%3E%20WSDL%20%3D%20DEFAULT%2C%20%3CBR%20%2F%3E%20DATABASE%20%3D%20'master'%2C%20%3CBR%20%2F%3E%20NAMESPACE%20%3D%20'%3CA%20href%3D%22http%3A%2F%2FtempUri.org%2F%22%20target%3D%22_blank%22%20rel%3D%22nofollow%20noopener%20noreferrer%22%3Ehttp%3A%2F%2FtempUri.org%2F%3C%2FA%3E'%20%3CBR%20%2F%3E%20)%3B%20%3CBR%20%2F%3E%3CP%3EThe%20reason%20behind%20the%20empty%20DataSet%20is%20because%20when%20the%20XSD%20schema%20for%20the%20resultset%20is%20not%20returned%20in%20the%20response%2C%20the%20DataSet%20object%20has%20no%20mechanism%20to%20determine%20what%20the%20table%20structure%20is%20(ie.%20how%20many%20columns%20are%20there%20and%20what%20the%20data%20type%20is%20for%20each%20of%20the%20columns).%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EThis%20problem%20can%20be%20resolved%20by%20either%20updating%20the%20webmethod%20(recommended)%20keyword%20%22SCHEMA%22%20to%20%22STANDARD%22%20or%2C%20updating%20the%20%22FOR%20SOAP%22%20section%20keyword%20%22SCHEMA%22%20to%20%22STANDARD%22.%3C%2FP%3EALTER%20ENDPOINT%20sql_endpoint%20%3CBR%20%2F%3E%20FOR%20SOAP%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20ALTER%20WEBMETHOD%20'foobar'%20(name%3D'myDatabase.dbo.sp_foobar'%2C%20SCHEMA%3DSTANDARD)%20%3CBR%20%2F%3E%20)%3B%20%3CBR%20%2F%3E%20or%20%3CBR%20%2F%3E%20ALTER%20ENDPOINT%20sql_endpoint%20%3CBR%20%2F%3E%20FOR%20SOAP%20%3CBR%20%2F%3E%20(%20%3CBR%20%2F%3E%20SCHEMA%3DSTANDARD%20%3CBR%20%2F%3E%20)%3B%20%3CBR%20%2F%3E%3CP%3EPlease%20note%20that%20by%20default%20the%20SCHEMA%20keyword%20within%20the%20WEBMETHOD%20section%20is%20set%20to%20%22DEFAULT%22%2C%20which%20means%20it%20defers%20to%20the%20SCHEMA%20setting%20for%20the%20SOAP%20endpoint.%20The%20default%20setting%20for%20the%20SOAP%20endpoint%20when%20the%20SCHEMA%20keyword%20is%20not%20specified%20within%20the%20FOR%20SOAP%20section%20is%20STANDARD.%20So%2C%20the%20scenario%20where%20this%20problem%20occurs%20would%20exist%20only%20if%20some%20one%20explicitly%20specified%20%22NONE%22%20for%20the%20SCHEMA%20keyword.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EPlease%20refer%20to%20CREATE%20ENDPOINT%20and%20ALTER%20ENDPOINT%20in%20Books%20Online%20for%20complete%20details.%3C%2FP%3E%3CBR%20%2F%3E%3CP%3EJimmy%20Wu%2C%20SQL%20Server%20Protocols%20%3CBR%20%2F%3E%20Disclaimer%3A%20This%20posting%20is%20provided%20%22AS%20IS%22%20with%20no%20warranties%2C%20and%20confers%20no%20rights%20%3CBR%20%2F%3E%3C%2FP%3E%0A%20%0A%3C%2FLINGO-BODY%3E%3CLINGO-TEASER%20id%3D%22lingo-teaser-383026%22%20slang%3D%22en-US%22%3EFirst%20published%20on%20MSDN%20on%20Oct%2010%2C%202005%20When%20using%20a%20Visual%20Studio%202005%20application%20to%20retrieve%20a%20SELECT%20statement%20resultset%20through%20SQL%202005%20native%20web%20services%2C%20the%20resultset%20is%20de-serialized%20from%20the%20wire%20format%20into%20a%20DataSet%20object.%3C%2FLINGO-TEASER%3E%3CLINGO-LABS%20id%3D%22lingo-labs-383026%22%20slang%3D%22en-US%22%3E%3CLINGO-LABEL%3ESQLServerProtocols%3C%2FLINGO-LABEL%3E%3C%2FLINGO-LABS%3E
Version history
Last update:
‎Mar 23 2019 04:10 AM
Updated by: