[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

HamuNaptra

1/5/2003 5:38:00 PM

I used to work a lot with MySQL in vb6,
now I'm migrating to vb.net, but I have some difficulties connecting to MySQL.

Can somebody please show me some working code?

I tried ByteFX (http://sourceforge.net/projects...)

This is my code:
*************************
Dim str As String
Dim mConn As MySQLConnection
mConn = New
MySQLConnection("DATABASE=SiteTracker;Driver=mysql;SERVER=localhost;UID=hamu;PWD
=naptra;PORT=3306;OPTION=131072;STMT=;")
str = "create table test (nr int(2));"
Dim mCommand As MySQLCommand
mCommand = New MySQLCommand(str, mConn)
Try
mConn.Open()
mCommand.ExecuteNonQuery()
MessageBox.Show("Database is created successfully",
"MyProgram",MessageBoxButtons.OK, MessageBoxIcon.Information)
Catch ex As Exception
' MessageBox.Show(ex.ToString())
txtLog.AppendText(ex.ToString)
Finally
If (mConn.State = ConnectionState.Open) Then
mConn.Close()
End If
End Try
*************************

But I get this error at mConn.Open():

*************************
System.NullReferenceException: Object reference not set to an instance of an
object.
at ByteFX.Data.MySQLClient.Driver.Authenticate(String userid, String
password, Boolean UseCompression)
at ByteFX.Data.MySQLClient.Driver.Open(String host, Int32 port, String
userid, String password, Boolean UseCompression)
at ByteFX.Data.MySQLClient.MySQLConnection.Open()
at SiteTracker.SiteTracker.cmdCreateDB_Click(Object sender, EventArgs e) in
V:\SiteTracker\frmSiteTracker.vb:line 299
*************************


4 Answers

Anthony Yio

1/6/2003 3:28:00 AM

0

U NEED TO DOWNLOAD ODBC.NET DRIVER IN microsoft.com.
U will need to use ODBCConnection class for initiating connection.
Import microsoft.data.odbc.



"HamuNaptra" <hamunaptra@pandora.be.NOSPAM> дÈëÏûÏ¢ÐÂÎÅ
:NbZR9.90124$Ti2.12759@afrodite.telenet-ops.be...
> I used to work a lot with MySQL in vb6,
> now I'm migrating to vb.net, but I have some difficulties connecting to
MySQL.
>
> Can somebody please show me some working code?
>
> I tried ByteFX (http://sourceforge.net/projects...)
>
> This is my code:
> *************************
> Dim str As String
> Dim mConn As MySQLConnection
> mConn = Newco
>
MySQLConnection("DATABASE=SiteTracker;Driver=mysql;SERVER=localhost;UID=hamu
;PWD
> =naptra;PORT=3306;OPTION=131072;STMT=;")
> str = "create table test (nr int(2));"
> Dim mCommand As MySQLCommand
> mCommand = New MySQLCommand(str, mConn)
> Try
> mConn.Open()
> mCommand.ExecuteNonQuery()
> MessageBox.Show("Database is created successfully",
> "MyProgram",MessageBoxButtons.OK, MessageBoxIcon.Information)
> Catch ex As Exception
> ' MessageBox.Show(ex.ToString())
> txtLog.AppendText(ex.ToString)
> Finally
> If (mConn.State = ConnectionState.Open) Then
> mConn.Close()
> End If
> End Try
> *************************
>
> But I get this error at mConn.Open():
>
> *************************
> System.NullReferenceException: Object reference not set to an instance of
an
> object.
> at ByteFX.Data.MySQLClient.Driver.Authenticate(String userid, String
> password, Boolean UseCompression)
> at ByteFX.Data.MySQLClient.Driver.Open(String host, Int32 port, String
> userid, String password, Boolean UseCompression)
> at ByteFX.Data.MySQLClient.MySQLConnection.Open()
> at SiteTracker.SiteTracker.cmdCreateDB_Click(Object sender, EventArgs
e) in
> V:\SiteTracker\frmSiteTracker.vb:line 299
> *************************
>
>


Steve Hindmarsh

1/8/2003 4:12:00 PM

0

It's then simply a case of setting up a connection using=20
the MySQL ODBC 3.51 driver in the ODBC Control Panel and=20
then using a connection string like "DSN=3DDatabaseName".

Easy, but a right fanny on if you don't already know!
Steve Hindmarsh

>-----Original Message-----
>U NEED TO DOWNLOAD ODBC.NET DRIVER IN microsoft.com.
>U will need to use ODBCConnection class for initiating=20
connection.
>Import microsoft.data.odbc.
>
>
>
>"HamuNaptra" <hamunaptra@pandora.be.NOSPAM> =
=D0=B4=C8=EB=CF=FB=CF=A2=D0=C2=CE=C5
>:NbZR9.90124$Ti2.12759@afrodite.telenet-ops.be...
>> I used to work a lot with MySQL in vb6,
>> now I'm migrating to vb.net, but I have some=20
difficulties connecting to
>MySQL.
>>
>> Can somebody please show me some working code?
>>
>> I tried ByteFX=20
(http://sourceforge.net/projects...)
>>
>> This is my code:
>> *************************
>> Dim str As String
>> Dim mConn As MySQLConnection
>> mConn =3D Newco
>>
>MySQLConnection
("DATABASE=3DSiteTracker;Driver=3Dmysql;SERVER=3Dlocalhost;UID=3Dh
amu
>;PWD
>> =3Dnaptra;PORT=3D3306;OPTION=3D131072;STMT=3D;")
>> str =3D "create table test (nr int(2));"
>> Dim mCommand As MySQLCommand
>> mCommand =3D New MySQLCommand(str, mConn)
>> Try
>> mConn.Open()
>> mCommand.ExecuteNonQuery()
>> MessageBox.Show("Database is created successfully",
>> "MyProgram",MessageBoxButtons.OK,=20
MessageBoxIcon.Information)
>> Catch ex As Exception
>> ' MessageBox.Show(ex.ToString())
>> txtLog.AppendText(ex.ToString)
>> Finally
>> If (mConn.State =3D ConnectionState.Open) Then
>> mConn.Close()
>> End If
>> End Try
>> *************************
>>
>> But I get this error at mConn.Open():
>>
>> *************************
>> System.NullReferenceException: Object reference not=20
set to an instance of
>an
>> object.
>> at ByteFX.Data.MySQLClient.Driver.Authenticate
(String userid, String
>> password, Boolean UseCompression)
>> at ByteFX.Data.MySQLClient.Driver.Open(String host,=20
Int32 port, String
>> userid, String password, Boolean UseCompression)
>> at ByteFX.Data.MySQLClient.MySQLConnection.Open()
>> at SiteTracker.SiteTracker.cmdCreateDB_Click(Object=20
sender, EventArgs
>e) in
>> V:\SiteTracker\frmSiteTracker.vb:line 299
>> *************************
>>
>>
>
>
>.
>

HamuNaptra

1/8/2003 4:48:00 PM

0


>"Steve Hindmarsh" <s.hindmarsh@ukonline.co.uk> schreef in bericht
news:153601c2b728$56654f10$d5f82ecf@TK2MSFTNGXA12...
>It's then simply a case of setting up a connection using
>the MySQL ODBC 3.51 driver in the ODBC Control Panel and
>then using a connection string like "DSN=DatabaseName".
>
>Easy, but a right fanny on if you don't already know!
>Steve Hindmarsh

Meet my connectionstring:
(It's a working connectionstring, that's not the problem, ByteFX is my problem)

mConn = New
MySQLConnection("DATABASE=SiteTracker;Driver=mysql;SERVER=localhost;UID=hamu;PWD
=naptra;PORT=3306;OPTION=131072;STMT=;")




Kim Bach Petersen

1/11/2003 12:05:00 PM

0

> Can somebody please show me some working code?

The 'IBuySpy'-portal agains MySQL might inspire:

http://www.we...

Kim :o)