AW: [Mono-dev] URGENT: Odbc-Exception-Error

Jan Waiz hamburg at icomedv.de
Wed Aug 17 12:57:26 EDT 2005


Sebastien,

of course! It seems to be a Problem with the Combination Odbc/Postgre. It
MUST be that, because it is me who is doing that :-)

I will test other Driver tomorrow - today I am to tired for that :-)

Thanks for your Help. Will have a look to unixODBC and freeTDS.

Regards
Jan Waiz

-----Ursprüngliche Nachricht-----
Von: Sébastien Robitaille [mailto:sebastien.robitaille at croesus.com] 
Gesendet: Mittwoch, 17. August 2005 17:11
An: hamburg at icomedv.de
Cc: mono-devel-list at lists.ximian.com
Betreff: RE: [Mono-dev] URGENT: Odbc-Exception-Error

Jan,

I am using the ODBC .NET Provider to access a Sybase database.
On Linux, I am using unixODBC and freeTDS.

And yes, it works as expected.
I never used PostgreSQL, but my code works as-is on Sybase and SQL Server
with the following .NET providers on both Mono and MS.NET:
- SybaseClient
- SQLClient
- Odbc

Maybe your problem has something to do with the ODBC database driver you are
using?

Hope it helps.

Sébas

-----Original Message-----
From: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com]On Behalf Of Jan Waiz
Sent: August 17, 2005 10:23 AM
To: 'Sébastien Robitaille'
Cc: mono-devel-list at lists.ximian.com
Subject: AW: [Mono-dev] URGENT: Odbc-Exception-Error


Sebas,

Problem is, that the ODBC-Classes did not support named Parameters. When
doing as you describe, I got a Runtime-Error

Syntax-Error at Sign,,,

Did you use the ODBC-Classes ?

Regards
Jan Waiz

-----Ursprüngliche Nachricht-----
Von: Sébastien Robitaille [mailto:sebastien.robitaille at croesus.com]
Gesendet: Mittwoch, 17. August 2005 15:14
An: hamburg at icomedv.de
Cc: mono-devel-list at lists.ximian.com
Betreff: RE: [Mono-dev] URGENT: Odbc-Exception-Error

Hi,

maybe you should try something like this instead:

cStmnt = "UPDATE ComanySTD SET Name1=@Name1, Name2=@Name2 WHERE PKey=@PKey";

oCommand.Parameters.Add("@Name1", Textbox_Name1.Text.Trim() )
oCommand.Parameters.Add("@Name2", Textbox_Name2.Text.Trim() )
oCommand.Parameters.Add("@PKey", cPKey);
oCommand.ExecuteNonQuery()

Sébas

-----Original Message-----
From: mono-devel-list-bounces at lists.ximian.com
[mailto:mono-devel-list-bounces at lists.ximian.com]On Behalf Of Daniel
Morgan
Sent: August 17, 2005 8:13 AM
To: hamburg at icomedv.de
Cc: mono-devel-list at lists.ximian.com
Subject: Re: [Mono-dev] URGENT: Odbc-Exception-Error


Read up on MSDN documentation on System.Data.Odbc.OdbcCommand property
CommandText

The Odbc provider uses question mark placeholders. It does not support
named parameters. You have to use a SQL statement like:

SELECT * FROM SOME_TABLE WHERE SOME_ID = ?

In your parameters, it is positional, not named.

I noticed in your code your are mis-matching. In your SQL statement, you
have placeholders, but your creation of the parameters you are using
named parameters with an @ symbol. You can not do this.

cStmnt = “UPDATE ComanySTD SET ” +

“ Name1 = ?, ”

“ Name2 = ? ”

“ WHERE PKey = ‘” + cPKey + "‘”


oCommand.Parameters.Add(new OdbcParameter).Value =
Textbox_Name1.Text.Trim();

oCommand.Parameters.Add(new OdbcParameter).Value =
Textbox_Name2.Text.Trim();

oCommand.ExecuteNonQuery();

If Odbc does not work for you, try Npgsql instead to connect to PostgreSQL.

Jan Waiz wrote:

> HI All,
>
> view Days ago i postet Porblems with ODBC and Postgre.
>
> One Answer was testet without solving the Problem so I send it to
> bugzilla – without any Answer up to know.
>
> Now I am running in Timeproblems for the Project because I can’t
> finish important Parts of the Application and the Deadline will come!
> So I am coming in Trouble if I did not found a Solution. Be so kind
> and let me know:
>
> How did YOU work via ODBC with a SQL-Database – meaning: How did you
> build Insert- or Updatestatements? And how did you solve the Problem
> with escaping Signs like <’> or german Signs like “äöü” ? Or did you
> work with an other SQL-Database in the descriped way without any
> Problems (*s*) ?
>
> In short I am doing it 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()
>
> wich is working fine running under Localhost but makes an Error
> running under Mono:
>
>System.Data.Odbc.OdbcException: [unixODBC]Unrecognized C_parameter type in
copy_statement_with_parameters
>
>
>
> When changing to:
>
> cStmnt = “UPDATE ComanySTD SET” +
>
> “Name1 = “ + Textbox_Name1.Text.Trim() + ,”
>
> “Name2 = “ + Textbox_Name2.Text.Trim() + ,”
>
> “WHERE PKey = ‘” + cPKey + ‘”
>
> It works. But without excaping! And Signs like “äöü” will shown as
> Crashed-Signs in a Textbox when showing a Record.
>
> I am playing around with different Ways using Parameter like:
>
> oCommand.Parameters.Add( “@Name1”, OdbcType.varchar, 36 ).Value =
> Textbox_Name1.Text.Trim()
>
> but everytime the same Runtimeerror.
>
> So – now I am at the end of my Nerves and my Knowledge. Hope, there is
> anyone outside there, who can tell me, how he is using ODBC-Parameter

>
> Many Thanks for ANY Help !!!
>
> Jan Waiz
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Mono-devel-list mailing list
>Mono-devel-list at lists.ximian.com
>http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
>

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list

_______________________________________________
Mono-devel-list mailing list
Mono-devel-list at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/mono-devel-list




More information about the Mono-devel-list mailing list