Calling a stored procedure SQL

Viewed 147

I'm trying to make a login to SQL and calling a DB storred procedure but I get some output I don't really understand. Here is my code:

using System;
using System.Configuration;
using System.Data;
using System.Data.SqlClient;
using System.Web;

public partial class Sendcode3 : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        HttpRequest currentRequest = HttpContext.Current.Request;
        String id = Server.UrlEncode(Request.QueryString["id"]);
        String pw = Server.UrlEncode(Request.QueryString["pw"]);
        String ip = "127.0.0.1";//currentRequest.ServerVariables["HTTP_X_FORWARDED_FOR"];
        int ret = 0;
        //if (ip == null || ip.ToLower() == "unknown")
        //    ip = currentRequest.ServerVariables["REMOTE_ADDR"];
        //if (id == "")
        //    Response.Write("-99");

        try
        {
            string connString = ConfigurationManager.ConnectionStrings["RohanUser"].ConnectionString;
            SqlConnection sqlConn = new SqlConnection(connString);
            string query = "call [dbo].[ROHAN3_SendCode](@id,@pw,@ip,@ret)";
            SqlCommand myCommand = new SqlCommand(query);
            myCommand.Parameters.AddWithValue("id", id);
            myCommand.Parameters.AddWithValue("pw", pw);
            myCommand.Parameters.AddWithValue("ip", ip);
            myCommand.Parameters.Add("ret", SqlDbType.Int).Direction = ParameterDirection.Output;

            myCommand.Connection = sqlConn;
            sqlConn.Open();
            if (myCommand.ExecuteNonQuery() > 0)
            {
                //ret = int.Parse(myCommand.Parameters["ret"].Value.ToString());
                ret = -202;
            }
            myCommand.Connection.Close();
            sqlConn.Close();

            Response.Write(ret);
        }
        catch (Exception ex)
        {
            Response.Write(ex.ToString());
        }
    }
}

The output I get is the following:

System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near '.'. at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) at System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString, Boolean isInternal, Boolean forDescribeParameterEncryption) at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, Boolean inRetry, SqlDataReader ds, Boolean describeParameterEncryptionRequest) at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean& usedCache, Boolean asyncWrite, Boolean inRetry) at System.Data.SqlClient.SqlCommand.ExecuteNonQuery() at Sendcode3.Page_Load(Object sender, EventArgs e) in c:\Users\Mihai\Documents\Visual Studio 2017\WebSites\RohanAuth\sendcode3.aspx.cs:line 34 ClientConnectionId:860145ab-56e5-496a-8d1a-ea39cf2c93e1 Error Number:102,State:1,Class:15

What am I missing? I can't seem to figure out what is the problem

2 Answers
Related