Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7555993
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T11:45:39+00:00 2026-05-30T11:45:39+00:00

I am trying to connect to a SQL Server 2008 database through a C#

  • 0

I am trying to connect to a SQL Server 2008 database through a C# program using a ODBC connection. I am sending a stored procedure some data in order to update some records. I would like to get back some sort of output messages to ensure my Proc is running. Before I started messing around with the output message, my proc ran, according to my C# program, it never returned an error. But the database was not updated. Once I added the code to allow for output, I got an error, something along the lines of HY105. Here comes the code:

Proc-

ALTER PROCEDURE [dbo].[Proc]
(   @userid                                 char(10),
@sql_userid                         varchar(50),
@user_encrypted_password        varchar(50),
@user_old_sql_guid_password     varchar(50),
@user_new_sql_guid_password     varchar(50),
    @user_new_sql_guid_encrypted_password   varchar(50),
    @errmsg                 int OUTPUT

)

as

DECLARE @now            datetime,
    @status         int,
    @InProcErrMsg   varchar(255)

SET @userid = UPPER(@userid)

BEGIN TRY  

EXEC ("ALTER LOGIN" + @sql_userid + "WITH PASSWORD  = " +
    @user_new_sql_guid_password + 
            " old_password = " + @user_old_sql_guid_password);

SET @errmsg = 0

IF @@ERROR = 0
    BEGIN
    UPDATE  Table
    Set     SERVER_OTHER = @user_new_sql_guid_encrypted_password
    WHERE   PC_LOGIN = @userid
            and PC_OTHER = @user_encrypted_password

    END 
SET @errmsg = 1
End try

begin catch
if @@trancount > 0
    rollback transaction

select @InProcErrMsg = left( "Proc: (" + cast( error_line() as varchar(10) ) + ") " 
+ error_message(), 255 )
raiserror 50000 @InProcErrMsg

end catch

return 0`

C#-

using (OdbcConnection databaseConnection = new OdbcConnection
                     ("Driver={SQLServer};Server=server;UID=id;PWD=pw;Database=db;"))
   {
     try
        {
         OdbcCommand SQLUserUpdateCommand = new OdbcCommand
           ("{? = CALL USP_PHD_SQLUSER_UPDATE(?,?,?,?,?,?)}", databaseConnection);

         SQLUserUpdateCommand.CommandType = CommandType.StoredProcedure;

         OdbcParameter SQLUserUpdateParam = SQLUserUpdateCommand.Parameters.Add
                                             ("@userid", OdbcType.Char, 10);
         SQLUserUpdateParam.Value = id;

         SQLUserUpdateParam = SQLUserUpdateCommand.Parameters.Add
                              ("@sql_userid", OdbcType.VarChar, 50);
         SQLUserUpdateParam.Value = sqlid;

         SQLUserUpdateParam = SQLUserUpdateCommand.Parameters.Add
                              ("@user_encrypted_password", OdbcType.VarChar, 50);
         SQLUserUpdateParam.Value = pw;

         SQLUserUpdateParam = SQLUserUpdateCommand.Parameters.Add
                              ("@user_old_sql_guid_password", OdbcType.VarChar, 50);
         SQLUserUpdateParam.Value = oldpw;

         SQLUserUpdateParam = SQLUserUpdateCommand.Parameters.Add
                              ("@user_new_sql_guid_password", OdbcType.VarChar, 50);
         SQLUserUpdateParam.Value = newpw;

         SQLUserUpdateParam = SQLUserUpdateCommand.Parameters.Add
                       ("@user_new_sql_guid_encrypted_password", OdbcType.VarChar, 50);
         SQLUserUpdateParam.Value = as_encrypted;

         SQLUserUpdateParam = SQLUserUpdateCommand.Parameters.Add
                              ("@errmsg", OdbcType.VarChar, 255);
         SQLUserUpdateParam.Direction = ParameterDirection.Output;

         databaseConnection.Open();

         SQLUserUpdateCommand.ExecuteNonQuery();

         SQLUserUpdateCommand.Dispose();
         databaseConnection.Close();
         }
         catch (OdbcException OEx)
         {
         Trace.WriteLine("Failed to call USP_PHD_SQLUSER_UPDATE");
         Trace.WriteLine("ODBC Exception Message: " + OEx.Message);
         Trace.WriteLine("ODBC Exception Source: " + OEx.Source);
         Trace.WriteLine("ODBC Exception StackTrace: " + OEx.StackTrace);
         Trace.WriteLine("ODBC Exception TargetSite: " + OEx.TargetSite);
         Trace.WriteLine("ODBC Exception Data: " + OEx.Data);
         Trace.WriteLine("ODBC Exception Error Code: " + OEx.ErrorCode);
         Trace.WriteLine("ODBC Exception Errors: " + OEx.Errors);
         }
       }

Error-

A first chance exception of type ‘System.Data.Odbc.OdbcException’ occurred in
System.Data.dll
Failed to call Proc
ODBC Exception Message: ERROR [HY105] [Microsoft][ODBC SQL Server Driver]Invalid
parameter type
ODBC Exception Source: SQLSRV32.DLL
ODBC Exception StackTrace:
at System.Data.Odbc.OdbcConnection.HandleError(OdbcHandle hrHandle, RetCode retcode)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior
behavior,
String method, Boolean needReader, Object[] methodArguments, SQL_API odbcApiMethod)
at System.Data.Odbc.OdbcCommand.ExecuteReaderObject(CommandBehavior
behavior, String method, Boolean needReader)
at System.Data.Odbc.OdbcCommand.ExecuteNonQuery()
at nvo_connect1.of_update(String as_process_name, String as_switch,
String as_server_signon, String as_server, String as_database,
String as_password, String as_decrypted, String as_new_password_guid,
String as_encrypted, String as_400_connection_string)
ODBC Exception TargetSite: Void HandleError(System.Data.Odbc.OdbcHandle, RetCode)
ODBC Exception Data: System.Collections.ListDictionaryInternal
ODBC Exception Error Code: -2146232009
ODBC Exception Errors: System.Data.Odbc.OdbcErrorCollection

It doesn’t give me a line number, but through testing, I know the error occurs at SQLUserUpdateCommand.ExecuteNonQuery();.

If there is such thing as too much info on this site, this is it. If so, apologies. First time user.

I have scoured Google for help way too much this week with no results. I know its gonna be a forehead slapper but that’s better than the current table-head-bang.

Thank you for any help.

Edit:

The @errmsg thing was important, so thank you for pointing that out. I changed my C# a bit to get this to finally work:

SQLUserUpdateCommand.Connection = databaseConnection;

//*****Open ODBC Connection
databaseConnection.Open();

SQLUserUpdateCommand.CommandType = CommandType.StoredProcedure;

SQLUserUpdateCommand.Parameters.AddWithValue("@userid", as_login_name);
SQLUserUpdateCommand.Parameters.AddWithValue("@sql_userid", as_server_signon);

SQLUserUpdateCommand.Parameters.AddWithValue("@user_encrypted_password", as_password);

SQLUserUpdateCommand.Parameters.AddWithValue("@user_old_sql_guid_password",
                                                                    as_decrypted);

SQLUserUpdateCommand.Parameters.AddWithValue("@user_new_sql_guid_password",
                                                              as_new_password_guid);

SQLUserUpdateCommand.Parameters.AddWithValue("@user_new_sql_guid_encrypted_password",
                                                              as_encrypted);

SQLUserUpdateCommand.ExecuteNonQuery();

Instead of using the ODBCParameter object to add my parameters, I added the parameters with the AddValue() method of the ODBCCommand object.

I got rid of the output parameter all together. Decided to retrieve error msgs by inserting records into a table. There were some issues with my alter statement as well. Overall, I do not know what the problem was. I am working with another proc in this same program that will be using output parameters, so any suggestions would be appreciated!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T11:45:40+00:00Added an answer on May 30, 2026 at 11:45 am

    This is wrong

    SQLUserUpdateParam = SQLUserUpdateCommand.Parameters.Add
                                  ("@errmsg", OdbcType.VarChar, 255);
    

    Because the parameter is declared this way in the procedure

          @errmsg        int OUTPUT
    

    You should update the C# code to match e.g.

    SQLUserUpdateParam = SQLUserUpdateCommand.Parameters.Add
                                  ("@errmsg", OdbcType.Int,);
    SQLUserUpdateParam.Direction = ParameterDirection.Output; 
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I want to connect to a remote database (SQL Server 2008) through code using
I've just installed SQL Server 2008 Developer edition and I'm trying to connect using
I am trying to connect the Sql Server 2008 R2 with java using JDBC.I
I'm trying to connect to SQL Server 2008 express database from Visual Studio 2010
I am trying to connect to SQL Server 2008 using 'sa' username and its
I'm trying to connect to an SQL Server 2008 database in a shared hosting
I am trying to connect the sql server database using 'sa' from my .Net
I am trying to connect to SQL Server 2008 server from Java here is
I'm trying to connect to SQL Server on Ubuntu 9.04 using Ruby. I translated
I'm trying to connect to a MS SQL Server 2005 Express database that is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.