hello everyone,
I am using VS 2005 and sql server 2000. I have a web application which uses a connectionstring with a user id and pwd. Everything is fine, I can execute normal sql statements from the code behind. I cannot execute a stored procedure...I get this error.
Could not locate entry in sysdatabases for database 'exec usp_add2DB (my parameters are included here, deleted for simplicity reasons)
No entry found with that name. Make sure that the name is entered correctly.
I have given execute permission for the user, and the name of the storedproc is correct. the name of the server is also correct...pls pls help me what is wrong here...
Post the code you have and someone here can help.|||
Thank you for the response.here is the code...shortened for simplicity sake.
BtnClick event:
string sql = exec sp_add2DB '" + tShiptoSiteNo.Text +"','" txtShipToSiteName.Text
ClassA a = new ClassA("dev_connectionstr");
if(a.ExecuteSP(sql))
{
Response.Write("executed");
}
I am using enterprise library 2.0: (Everything is set up properly,pretty confident about it ,because many apps i am using it).
In Class A:
public class A :BaseDAO
{
public bool ExecuteSP(string sql)
{
DbCommand dbCommand = SqlDatabase.GetStoredProcCommand(sql);
int a = SqlDatabase.ExecuteNonQuery(dbCommand);
return true;}
In web.config:
<connectionStrings>
<add name ="dev_connectionstr" connectionString ="Data Source=ServerName;Initial Catalog=TestDB;User ID=test_user;Password=xxxx" providerName ="System.Data.SqlClient"/>
</connectionStrings>
Thanks for the help.
Hi sankar,
When executing a stored procedure, you cannot list your parameters after the stored procedure name and execute with EXEC.
You need to create a SqlCommand object, and make CommandText as "sp_add2DB". Then use SqlCommand.Parameters.Add() method to add the parameters one by one. After this is done, open the connection and call SqlCommand.ExecuteNonQuery to execute it.
|||Thanks a lot for the reply Kevin Yu....tht explains why! Thank you very much!.
No comments:
Post a Comment