Unable to pass SqlParameter object to a web service function

A

arun gunda

I am trying to create a webservice for executing a stored
procedure. This webservice is just a wrapper class for
Microsoft.ApplicationBlocks.Data Functions. I will pass
the database name, stored procedure name and sql parameter
object. I am able to create webservice I mentioned below,
but It only works from .Net C# Windows Form but when I try
to use it from ASP.Net c#, I am unable to compile. it
looks like it is unable to resolve namespace for
sqlparameter

Any ideas why this happens?

[WebMethod]
public System.Data.DataSet ExecuteSP(string databasename,
string spname, params System.Data.SqlClient.SqlParameter[]
commandParameters)
{
System.Data.DataSet ds;


//read database connection string
string connectstring = Application[databasename].ToString
();

// SqlConnection that will be used to execute the sql
commands
SqlConnection connection = null;
try
{
connection = new SqlConnection(connectstring);
//Open Connection
connection.Open();
ds = SqlHelper.ExecuteDataset(connection,
CommandType.StoredProcedure, spname, commandParameters);
}
catch(Exception ex)
{
throw ex;
}
finally
{
if(connection != null)
connection.Dispose();
}
return ds;
}
}
 
D

Doug Treleaven

When you try to pass the SqlParameter object from a web client (ASP.Net web
service) it will try to serialize the object into XML - which it cannot do.
In order to get it to work from the client you will need to pass the value
of the parameter and create the parameter object within the web method on
the server.

I see that you are trying to create a "reusable" method - what you could do
instead is create your own class that includes a custom parameter object
type that you can serialize properly - like an array of structures would be
the easiest way. Then on the server side you can easily gain access to all
the parameter names, data types, and values, which you can create the
SqlParameter objects from.

I trust this helps.

Thanks,
Doug Treleaven
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,074
Latest member
StanleyFra

Latest Threads

Top