Hi. I have problem with Stored Procedures and Windows Application.
I don't know what's wrong with them, but they are going on my nervse.
This is Stored Procedure I want to EXECUTE:
[code]
ALTER PROCEDURE spFormSiteOptionsSet
(
@DISABLE_LOGIN bit,
@DISABLE_BUYERS_REGISTRATION bit,
@DISABLE_PROGRAMMERS_REGISTRATION bit,
@LOCK_SITE bit,
@PERCENTS int,
@MIN_ACCOUNT_AMOUNT_BUYERS int,
@MIN_ACCOUNT_AMOUNT_PROGRAMMERS int,
@MAX_AUTOSEND_AMOUNT int,
@FINISHED_PROJECTS_AMOUNT int,
@UPLOAD_EXTENSIONS nvarchar(250)
)
AS
BEGIN
SET NOCOUNT ON
UPDATE [tblOptions] SET disable_login =
@DISABLE_LOGIN, disable_buyers_registration =
@DISABLE_BUYERS_REGISTRATION, disable_programmers_registration =
@DISABLE_PROGRAMMERS_REGISTRATION, lock_site = @LOCK_SITE, percents =
@PERCENTS, min_account_amount_buyers = @MIN_ACCOUNT_AMOUNT_BUYERS,
min_account_amount_programmers = @MIN_ACCOUNT_AMOUNT_PROGRAMMERS,
max_autosend_amount = @MAX_AUTOSEND_AMOUNT, finished_projects_amount =
@FINISHED_PROJECTS_AMOUNT, upload_extensions = @UPLOAD_EXTENSIONS
SET NOCOUNT OFF
END
[/code]
I know I can use it in regular SQL query like EXECUTE spName
parameter1, parameter2..., but I don't wanna do like this becouse it is
not very well readable.
I prefer line for each parameter.
I've created Connection class (MSSqlConn) and I've create a new instance of that class.
In that class, I have spOpenConn() and spExecute() (besides other functions).
First function take one argument (spname) and second function executes the SP.
(code for those two function are at the bottom of the page).
The code I use for SP execution is below.
This code raises an error (System error pointing on
s.cmd.ExecuteNonQuery()). Same error is raised even if I put
ExecuteReader or ExecuteScalar insted of ExecuteNonQuery.
[code]
MSSqlConn s = new MSSqlConn();
s.spOpenConn("spFormSiteOptionsSet");
s.cmd.Parameters.Add("@DISABLE_LOGIN", SqlDbType.Bit).Value = Convert.ToInt32(Options.DisableLogin);
s.cmd.Parameters.Add("@DISABLE_BUYERS_REGISTRATION", SqlDbType.Bit).Value = Convert.ToInt32(Options.DisableBuyersRegistration);
s.cmd.Parameters.Add("@DISABLE_PRORGAMMERS_REGISTRATION",
SqlDbType.Bit).Value =
Convert.ToInt32(Options.DisableProgrammersRegistration);
s.cmd.Parameters.Add("@LOCK_SITE", SqlDbType.Bit).Value = Convert.ToInt32(Options.LockSite);
s.cmd.Parameters.Add("@PERCENTS", SqlDbType.Int).Value = Convert.ToInt32(Options.Percent);
s.cmd.Parameters.Add("@MIN_ACCOUNT_AMOUNT_BUYERS", SqlDbType.Int).Value = Convert.ToInt32(Options.minAccountAmountBuyers);
s.cmd.Parameters.Add("@MIN_ACCOUNT_AMOUNT_PROGRAMMERS",
SqlDbType.Int).Value =
Convert.ToInt32(Options.MinAccountAmountProgrammers);
s.cmd.Parameters.Add("@MAX_AUTOSEND_AMOUNT", SqlDbType.Int).Value = Convert.ToInt32(Options.MaxAutosendAmount);
s.cmd.Parameters.Add("@FINISHED_PROJECTS_AMOUNT", SqlDbType.Int).Value = Convert.ToInt32(Options.FinishedProjectAmount);
s.cmd.Parameters.Add("@UPLOAD_EXTENSIONS", SqlDbType.Char).Value = Convert.ToString(Options.UploadExtensions);
s.spExecute();
[/code]
spOpenConn function code:
[code]
public void spOpenConn(string spName)
{
con = new SqlConnection(connString); // Connection String is valid
con.Open();
connBool = true;
try
{
if (connBool)
{
CloseRead(); // in case that reader isn't closed it closes him (same
error with or without this line)
cmd = new SqlCommand(spName, con);
cmd.CommandType = CommandType.StoredProcedure;
}
}
finally
{
}
}
[/code]
spExecute function code:
[code]
public void spExecute()
{
cmd.ExecuteNonQuery();
CloseConn();
}
[/code]
What is the problem. Iam going crazy.
Error that raise:
An unhandled exception of type 'System.Data.SqlClient.SqlException' occurred in system.data.dll
Additional information: System error.

Windows Application have problem with Stored Procedure...
Arjan Ligthart
My mistake.
Umut Alev - MSFT
pogsworth
I was furious because code didn't work as I expected.
Sorry again.