ODBC driven ASP.NET application running on iis doesn't work on speceific system

0

I'm having a strange problem with IIS, asp.net and ODBC. My application is driven by SQL server via ODBC driver (I know it's bad practice, but my entire DAL is already written and will not be changed). The problem is that when I run an SP with my web interface, on any other computer other than the production server it works fine, but on the production server I get the following error:

Exception Message: System.Data.Odbc.OdbcException (0x80131937): ERROR [42000] [Microsoft] [ODBC SQL Server Driver][SQL Server]Error converting data type nvarchar to int

Obviously when I run it under management studio it works fine. I think the problem is somewhere between the IIS and the odbc driver, but I'm not sure exactly where.

I'm running .net framework 4.

This is the calling method:

ODBCComm command = new ODBCComm();          
        command.Query = "SP_web_update_calls_dest @id=?,@name=? ,@ivrCode=?,@DDI=?,@destType=?,@trkGroup=?,@result=? output";
        command.AddInputParam(id);
        return AddParamsAndExecute(name, ivrCode, DDI, destType, trkGroup, command);

it basically wraps arround: OdbcCommand.ExecuteDirect();

Thanks a lot, Yuval.

asp.net
iis
odbc
asked on Stack Overflow Jun 24, 2012 by lavuy • edited Jun 24, 2012 by lavuy

2 Answers

0

I believe your first param is being used in the ID spot. I'm not sure why this would work in pre-production and fail only in production, but try this instead...

ODBCComm command = new ODBCComm();           
        command.Query = "SP_web_update_calls_dest @id=?,@name=? ,@ivrCode=?,@DDI=?,@destType=?,@trkGroup=?,@result=? output"; 

        return AddParamsAndExecute(id, name, ivrCode, DDI, destType, trkGroup, command); 

I have no idea what ODBCComm is or what AddParamsAndExecute does because you haven't included the relavant code, however, here's what the request should look like:

    OdbcCommand Cmd = new OdbcCommand("SP_web_update_calls_dest", _Connection); 
    Cmd.CommandType = CommandType.StoredProcedure; 

    Cmd.Parameters.Add("@id", OdbcType.Int); 
    Cmd.Parameters["@id"].Value = id; 

    Cmd.Parameters.Add("@name", OdbcType.NVarChar); 
    Cmd.Parameters["@name"].Value = name;

    Cmd.Parameters.Add("@ivrCode", OdbcType.Int); 
    Cmd.Parameters["@ivrCode"].Value = ivrCode; 

    Cmd.Parameters.Add("@DDI", OdbcType.VarChar); 
    Cmd.Parameters["@DDI"].Value = DDI;

    Cmd.Parameters.Add("@destType", OdbcType.Int); 
    Cmd.Parameters["@destType"].Value = destType; 

    Cmd.Parameters.Add("@trkGroup", OdbcType.Int); 
    Cmd.Parameters["@trkGroup"].Value = trkGroup; 

    Cmd.Parameters.Add("@result", OdbcType.Int); 
    Cmd.Parameters["@result"].Direction = ParameterDirection.Output;

    Cmd.ExecuteNonQuery(); 

    int result = (int)Cmd.Parameters["@result"].Value; 
answered on Stack Overflow Jun 24, 2012 by Chris Gessler • edited Jun 24, 2012 by Chris Gessler
0

OK, I think I solved it. There were actually 2 problems, and I'm not exactly sure what caused them. Anyway, I switched the ODBC driver to SQL Server Native Client 10. This basically solved the problem, but for some reason it doesn't support the output modifier in queries so I had to remove that.

So I got it solved, but still have no idea what caused the problem. I'm guessing it has something to do with different versions of drivers.

answered on Stack Overflow Jun 25, 2012 by lavuy

User contributions licensed under CC BY-SA 3.0