Thanks. It worked. My project compiles. But running it caused an
error:
Unhandled Exception: MySql.Data.MySqlClient.MySqlException: You have
an error in your SQL syntax; check the manual that corresponds to your
MySQL server version for the right syntax to use near '[ISBN],
[Title], [AvailableDate]
FROM [MySqlSampleDb].[Book]' at line 1
at MySql.Data.MySqlClient.MySqlStream.ReadPacket () [0x00000] in
<filename unknown>:0
at MySql.Data.MySqlClient.NativeDriver.GetResult (System.Int32&
affectedRow, System.Int32& insertedId) [0x00000] in <filename unknown>:
0
Here's my simple test code:
class MainClass
{
public static void Main (string[] args)
{
linqstylecode();
}
private static void linqstylecode()
{
IDbConnection dbcon;
dbcon = (IDbConnection) new
MySqlConnection("Server=localhost;
Database=MySqlSampleDb; User=user; Password=password;");
using (var db = new MySqlSampleDb(dbcon))
{
var books = from bk in db.Book
select (new {bkIsbn = bk.Isbn,
bkTitle=bk.Title,
bkAvailableDt=bk.AvailableDate});
foreach(var mybook in books)
{
Console.WriteLine(mybook.bkIsbn + ": "
+ mybook.bkTitle);
}
}
}
}
The MySql provider is fine because I tested it using ADO.NET as
below...
private static void adostylecode()
{
IDbConnection dbcon;
dbcon = (IDbConnection) new
MySqlConnection("Server=localhost;
Database=MySqlSampleDb; User=user; Password=password ");
dbcon.Open();
IDbCommand dbcmd = dbcon.CreateCommand();
string sql = "SELECT * FROM Book";
dbcmd.CommandText = sql;
IDataReader reader = dbcmd.ExecuteReader();
while(reader.Read())
{
string _isbn = reader.GetString(0);
string _title = reader.GetString(1);
// string _availableDt = reader.GetString(2);
Console.WriteLine("ISBN: " + _isbn + " Title:"
+ _title);
}
// cleanup
reader.Close();
reader = null;
dbcmd.Dispose();
dbcmd = null;
dbcon.Close();
dbcon = null;
}
I understand what the error is referring to but I am drawing blank as
to what part of the above code is causing this. Have anyone encounter
such issue with MySQL and DbLinq. Any ideas how to make it work?
Thanks.
On Sep 22, 10:33 am, Jonathan Pryor <[email protected]> wrote:
> On Tue, 2010-09-21 at 20:32 -0700, El wrote:
> > When I executed the command below:
>
> > sqlmetal /provider:MySql /server:localhost /database:MySqlSampleDb /
> > user:hansel /password:rpt4wr5 /pluralize /code=mysqlsampledb.cs
> ...
> > >>> Reading schema from MySQL database
> > sqlmetal: Client does not support authentication protocol requested by
> > server; consider upgrading MySQL client
>
> > I have the latest Mysql.Data.dll in my GAC.
>
> Not sufficient. sqlmetal is, for all intents and purposes, DbMetal,
> thus the following applies:
>
> http://code.google.com/p/dblinq2007/wiki/Installation#To_run_DbMetal
>
> Specifically the "There are three ways that the ADO.NET provider can be
> used with DbMetal.exe" section:
>
> If your ADO.NET provider is present within the Global Assembly
> Cache, you can edit DbMetal.exe.config (in the DbLinq
> installation directory) to use an assembly-qualified type name
> in the /configuration/providers/provider/@databaseConnection
> attribute.
>
> The default ADO.NET provider for MySQL is the ByteFX.Data provider. The
> advantage is that ByteFX is bundled with Mono, but it's also ancient
> (hence your authentication error). Thus, you should edit
> e.g. /usr/lib/mono/2.0/sqlmetal.exe.config and change the MySQL provider
> value. Alternatively...
>
> > I saw some links that
> > suggested adding the /databaseConnectionProvider.
>
> > sqlmetal /provider:MySql /
> > databaseConnectionProvider="MySql.Data.MySqlConnection, MySql.Data" /
> > server:localhost /database:MySqlSampleDb /user:hansel /
> > password:rpt4wr5 /debug /pluralize /code=mysqlsampledb.cs
>
> If your mono is anything recent, it's not /databaseConnectionProvider,
> it's --with-dbconnection. See 'sqlmetal /?' for details.. Furthermore,
> the value needs to be a fully qualified name, which yours isn't. Thus:
>
> sqlmetal /provider:MySql \
> --with-dbconnection="MySql.Data.MySqlClient.MySqlConnection,
> MySql.Data, Version=5.0.8.1, Culture=neutral,
> PublicKeyToken=c5687fc88969c44d" \
> /server:localhost /database:MySqlSampleDb \
> /user:user /password:password /debug /pluralize \
> /code:mysqlsampledb.cs
>
> Note that the above value comes from MySql.Data v5.0.8.1, so things may
> have changed [0].
>
> - Jon
>
> [0] Pro tip: to easily get the assembly qualified name,
> use /usr/bin/csharp:
>
> $ csharp -r:path/to/MySql.Data.dll
> csharp>
> typeof(MySql.Data.MySqlClient.MySqlConnection).AssemblyQualifiedName;
> "MySql.Data.MySqlClient.MySqlConnection, MySql.Data, Version=5.0.8.1,
> Culture=neutral, PublicKeyToken=c5687fc88969c44d"
--
You received this message because you are subscribed to the Google Groups
"DbLinq" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/dblinq?hl=en.