[Mono-list] problem with myodbc

danilo lujambio danilo@tau.org.ar
17 Aug 2003 23:57:08 -0300


Hi,

I have worked with myodbc with C# but I didn't have good results

I passed some steps that I read from lists ( like link libodbc32 to
liobdbc , etc ) and I am working with the code from
System.Data/Test/Odbc.Test.cs . 

Now I have an error about authentication on database, the user is OK and
the password is OK , I suspect that the connection string is wrong but I
could not find the error. My code is :

using System;
using System.Data;
using System.Data.Odbc;

namespace Test.OdbcTest
{
	class OdbcTest
	{
		[STAThread]
		static void Main(string[] args)
		{
			OdbcConnection dbcon = new OdbcConnection();
			dbcon.ConnectionString = 
				"DRIVER={MySQL};" + 
				"SERVER=localhost;UID=usuario;Password=clave;" +				"DATABASE =
midatabase";
//				"OPTION=3"; 

			// connection string that uses a DSN.
//			dbcon.ConnectionString = 
//				"DSN=LocalServer;UID=root;PWD=AA4Tmc";
				
			dbcon.Open();

			OdbcCommand dbcmd = new OdbcCommand();
			dbcmd.Connection = dbcon;
			dbcmd.CommandType = CommandType.Text;
			dbcmd.CommandText = "SELECT * FROM Cabinas";
			
			OdbcDataReader reader;
			reader = (OdbcDataReader) dbcmd.ExecuteReader();

			while(reader.Read()) {
				Console.WriteLine("Last Name: " + reader[0].ToString());
			}
			reader.Close();
			dbcmd.Dispose();
			dbcon.Close();
		}
	}
}

the error is :

Unhandled Exception: System.Data.Odbc.OdbcException:
[unixODBC][TCX][MyODBC]Access denied for user: 'danilo@localhost' (Using
password: NO)
in <0x004a1> 00 System.Data.Odbc.OdbcConnection:Open ()
in <0x00054> 08 System.Data.Odbc.OdbcConnection:Open ()
in <0x00059> 00 Test.OdbcTest.OdbcTest:Main (string[])

(I verified the user and password with mysql -u  user -p , etc)

can anybody help me ? or can anybody give me a working example ?

Thanks in advance !

danilo