[Mono-dev] Re: Only works on MySql 4.1!?

Robert Jordan robertj at gmx.net
Sat Mar 4 09:59:26 EST 2006


Paulo,

> I'm making a program in mono 1.1.13 using MySql.
> I am using the most recent version of the .NET connector dll, 1.0.7(?).
> I'm developing it in Linux with MySql 4.1.
> 
> - When i went to test it in Windows, i installed MySql 4.0. Some inserts
> would never work.
> - I then installed the most recent version, 5.0.1(?). Now, the ones who
> were failing became working but some other insterts stopped working.
> - I went to try against a new instalation of MySql, this time 4.1,
> everything worked fime.
> 
> All instalations on Windows were made with the default settings.
> I tried using the dll for mono, for .net 1.0 and .net 2.0. Apart from
> the 2.0 one who did not worked at all, the other 2 presented the exact
> same behaviour.
> 
> Can anyone help me out trying to figure out what might be wrong?

You're hiding the exceptions. Instead of

...
catch {
   ...
}

try something like that:

...
catch (Exception ex) {
   Console.WriteLine (ex);
   ...
}

The MySQL Connector's exceptions are pretty verbose, so you
should be able to deduct the problem from the output.

Robert



> 
> 
> 
> 
> 
> Here is the code i'm using to access the database:
> [code]
> ...
> ...
>                         comando= "insert into " + nomeTabela + " (" +
>                                 colunas + ") values (" + conteudo +
> ");";
>                         return BD.ExecutarComando (comando);
> ...
> ...
> 
>                 public static Retorno InicializarString ()
>                 {
>                         Retorno r= new Retorno();
> 
>                         conectString= "Server=" + servidor +
> ";Database=" + baseDados +
>                                 ";Uid=" + utilizador + ";Pwd=" + passe +
> ";";
>                         //"Encrypt=true;" "Allow Zero Datetime=
> true;Connect Timeout=15;"
> 
>                         r.sucesso= true;
>                         return r;
>                 }
> 
>                 public static Retorno ExecutarComando (string
> strComando)
>                 {
>                         if (conectString== "") InicializarString();
> 
>                         MySqlConnection ligacao= new MySqlConnection
> (conectString);
>                         MySqlCommand comando= new MySqlCommand
> (strComando);
>                         Retorno r= new Retorno();
> 
>                         comando.Connection= ligacao;
>                         try {
>                                 ligacao.Open();
>                         } catch {
>                                 r.sucesso= false;
>                                 r.resultadoStr= Textos.ligacaoFalhada;
>                                 return r;
>                         }
>                         try {
>                                 r.resultadoInt= comando.ExecuteNonQuery
> ();
>                                 ligacao.Close();
>                         } catch {
>                                 r.sucesso= false;
>                                 r.resultadoStr= Textos.comandoFalhado;
>                                 ligacao.Close();
>                                 return r;
>                         }
> 
>                         r.sucesso= true;
>                         return r;
>                 }
> ...
> ...
> [/code]
> 
> 




More information about the Mono-devel-list mailing list