[Mono-dev] Odbc-Exception-Error

tsureshkumar tsureshkumar at novell.com
Sat Aug 13 11:55:17 EDT 2005


Jan Waiz wrote:
> Hi Folks,
> big Trouble in China! J
> Working with ODBC on a PostgreSQL.
> While the ODBC did not support named Parameters and to be save about 
> Signs like the <’> in Textboxes, i am building my Update-Statements like 
> this:
> cStmnt = “UPDATE ComanySTD SET” +
>               “Name1 = ?,”
>               “Name2 = ?”
>               “WHERE PKey = ‘” + cPKey + ‘”
> oCommand.Parameters.Add( “@Name1”, Textbox_Name1.Text.Trim() )
> oCommand.Parameters.Add( “@Name2”, Textbox_Name2.Text.Trim() )
> oCommand.ExecuteNonQuery()
> 
> This works fine when starting under Localhost.
> 
> If running in Mono I get an Error:
> 
> System.Data.Odbc.OdbcException: [unixODBC]Unrecognized C_parameter type in copy_statement_with_parameters

Try setting odbc type explicitly.

OdbcParameter oParam = Command.Parameters.Add( “@Name1”, OdbcType.VarChar);
oParam.Value = Textbox_Name1.Text.Trim();

if it does not work,
please provide a sample table schema.  Did you verify your postgres odbc 
driver works fine (with C/perl/ms.net client) with the same query.

> When changing the Statement to:
> 
> cStmnt = “UPDATE ComanySTD SET” +
>               “Name1 = “ + Textbox_Name1.Text.Trim()  + ,”
>               “Name2 = “ + Textbox_Name2.Text.Trim()  + ,”
>               “WHERE PKey = ‘” + cPKey + ‘”
> 
> oCommand.ExecuteNonQuery()
> 
> it works with Mono – but if there is an <’> in a Textbox it crashes. So 
> I have to escape special Signs manuel.

yes. with the structure of the query, you have to escape the text 
entered by the user, as you are giving plain SQL query. odbccommand does 
not know which part of the query to escape.

> 
> I found one Entry in Google, where one Developer will have the same 
> Problem – but there wasn´t any Answers what to do.
> 
> Someone here who can help me what I have to do?

Please file a bug report at http://bugzilla.ximian.com with a small test 
code, table schema, version of postgres and postgres odbc driver. If 
possible attach a odbc trace log, with only this query running.

suresh.

> 
> Many Thanks in Advance for any Help !!
> Regards
> 
> Jan Waiz
> 



More information about the Mono-devel-list mailing list