Error connecting to MySql

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: Nov 2008
Posts: 7
Reputation: cutieann12 is an unknown quantity at this point 
Solved Threads: 0
cutieann12 cutieann12 is offline Offline
Newbie Poster

Error connecting to MySql

 
0
  #1
Dec 8th, 2008
hello everyone, i need to make a program that will show/load the images stored in mysql database, i've already created the database and my problem is i can't load it in my vb code....

here's my code below

Dim conn As MySqlConnection
'connect to database
conn = New MySqlConnection()
conn.ConnectionString = "server = localhost; id = root; password = mypass; database=face manager"

Try
conn.Open()
Catch myerror As MySqlException
MsgBox("Error connecting to database")
End Try

'sql query
Dim myAdapter As New MySqlDataAdapter

Dim sqlquery = "SELECT * FROM eyes"
Dim myCommand As New MySqlCommand()
myCommand.Connection = conn
myCommand.CommandText = sqlquery

'start query
myAdapter.SelectCommand = myCommand
Dim myData As MySqlDataReader
myData = myCommand.ExecuteReader()

thanks, i need any response
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 710
Reputation: Teme64 will become famous soon enough Teme64 will become famous soon enough 
Solved Threads: 114
Teme64's Avatar
Teme64 Teme64 is offline Offline
Master Poster

Re: Error connecting to MySql

 
0
  #2
Dec 8th, 2008
For some reason I didn't get DataReader to work. But with DataAdapter and DataSet I got images from DB. I used SQL Server but that shouldn't make any difference.
  1. 'start query
  2. ' Declare a DataSet object
  3. Dim Images As New DataSet()
  4.  
  5. myAdapter.Fill(Images, "Eyes")
  6. ' With DataAdapter you can close connection, with DataReader you have to keep connection open and close it at the end
  7. conn.Close()
  8.  
  9. ' Buffer to hold image data
  10. Dim ByteArr() As Byte
  11. Dim ImageIndex As Integer
  12. Dim i As Integer
  13.  
  14. ImageIndex = 0 ' Column index of images, set the right value in here
  15.  
  16. ' Loop all rows
  17. For i = 0 To Images.Tables(0).Rows.Count - 1
  18. ' Read a BLOB to buffer
  19. ByteArr = CType(Images.Tables(0).Rows.Item(i).Item(ImageIndex), Byte())
  20. ' Create a memory stream of the buffer
  21. Dim ImageStream As New MemoryStream(ByteArr)
  22. ' Get the image from the memory stream
  23. PictureBox1.Image = Image.FromStream(ImageStream)
  24. ' "Refresh" display
  25. Application.DoEvents()
  26. ' Wait 3 seconds
  27. System.Threading.Thread.Sleep(3000)
  28. Next i
You also have to import System.IO namespace to use memory stream.
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: Error connecting to MySql

 
0
  #3
Dec 11th, 2008
Hi!

Just verify these-

Do you have the MySQL Connector installed?

Are you sure your connection string is correct?
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote Quick reply to this message  
Join Date: Nov 2008
Posts: 7
Reputation: cutieann12 is an unknown quantity at this point 
Solved Threads: 0
cutieann12 cutieann12 is offline Offline
Newbie Poster

Re: Error connecting to MySql

 
0
  #4
Dec 11th, 2008
Originally Posted by tuse View Post
Hi!

Just verify these-

Do you have the MySQL Connector installed?

Are you sure your connection string is correct?
Yes, i have installed MySql Connector Net version 1.0.10.1 and the connection string was correct..
Reply With Quote Quick reply to this message  
Join Date: Jul 2007
Posts: 169
Reputation: tuse is an unknown quantity at this point 
Solved Threads: 14
tuse's Avatar
tuse tuse is offline Offline
Junior Poster

Re: Error connecting to MySql

 
0
  #5
Dec 11th, 2008
try this connection string-

  1. Server=myServerAddress;Database=myDataBase;Uid=myUsername;Pwd=myPassword;
My blog on .NET- http://dotnet.tekyt.info
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC