473,509 Members | 2,863 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to Connect to MYSQL5.1 from VS.Net2003

3 New Member
hi, am having problem connecting to MYSQL5.1 from VS.Net.the error is database reeor:System.Data.SqlClient.SqlException:An error occur while establishnig a connection to the server. Am Using Visual Studio.Net 2003, IIS 5.0 and MySql5.1. am trying to retreve a new record from a database using a webservice.

here is the sample code

Imports System
Imports System.Data
Imports System.Data.SqlClient
Imports System.Web.Services


<System.Web.Services.WebService(Namespace:="http ://tempuri.org/MyWebService1/Service1")> Public Class MyDataService1
Inherits System.Web.Services.WebService

#Region " Web Services Designer Generated Code "

Public Sub New()
MyBase.New()
'This call is required by the Web Services Designer.
InitializeComponent()
'Add your own initialization code after the InitializeComponent() call

End Sub

'Required by the Web Services Designer
Private components As System.ComponentModel.IContainer

'NOTE: The following procedure is required by the Web Services Designer
'It can be modified using the Web Services Designer.
'Do not modify it using the code editor.
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()

End Sub

Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
'CODEGEN: This procedure is required by the Web Services Designer
'Do not modify it using the code editor.
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub

#End Region

' WEB SERVICE EXAMPLE
' The HelloWorld() example service returns the string Hello World.
' To build, uncomment the following lines then save and build the project.
' To test this web service, ensure that the .asmx file is the start page
' and press F5.
'
'<WebMethod()> _
'Public Function HelloWorld() As String
' Return "Hello World"
'End Function

<WebMethod()> Public Function GetLastID() As String

Dim LastID As Integer
Dim sConn As String = "SERVER =localhost;DATABASE =db1 ;UID =root ;PWD = webserver ;"
Dim sComm As String = "SELECT ID FROM Table2 WHERE ID = MAX(ID)"

Dim conn As New SqlConnection(sConn)
Dim comm As New SqlCommand
Try
conn.Open()
comm.CommandText = (sComm)
comm.CommandType = CommandType.Text

If (comm.ExecuteScalar() Is Nothing) Then
Return comm.ExecuteScalar

Else
Return comm.ExecuteScalar
LastID = comm.ExecuteScalar

End If

Catch ex As SqlException
Return "Database error:" + ex.ToString

Catch ex As Exception
Return "error:" + ex.ToString
Finally
If (conn.State = ConnectionState.Open) Then
conn.Close()

End If

End Try

End Function
<WebMethod()> Public Function GetmaxID() As String

Dim MaxID As Integer
Dim sConn As String = "SERVER = localhost;DATABASE = db2 ;UID =root ;PWD = webserver;"
Dim sComm As String = "SELECT ID FROM Table1 WHERE ID = MAX(ID)"

Dim conn As New SqlConnection(sConn)
Dim comm As New SqlCommand
Try
conn.Open()
comm.CommandText = (sComm)
comm.CommandType = CommandType.Text

If (comm.ExecuteScalar() Is Nothing) Then
Return comm.ExecuteScalar

Else
Return comm.ExecuteScalar
MaxID = comm.ExecuteScalar

End If

Catch ex As SqlException
Return "Database error:" + ex.ToString

Catch ex As Exception
Return "error:" + ex.ToString
Finally
If (conn.State = ConnectionState.Open) Then
conn.Close()

End If

End Try

End Function
<WebMethod()> Public Function DectectNewRecord() As DataSet

Dim sConn As String = "SERVER = localhost;DATABASE = db1;UID = root;PWD = webserver;"
Dim sComm As String = "SELECT * FROM Table2 WHERE ID = MAX(ID)"

Dim LastID As Integer = GetLastID()
Dim MaxID As Integer = GetmaxID()
'test to confirm if there is new record
'if true it open connection into database1 and retrieve the record
'put it into a dataset

If (LastID > MaxID) Then
Dim da As New SqlClient.SqlDataAdapter(sConn, sComm)
Dim ds As New DataSet
da.Fill(ds, "NewRecord")
Return ds
Else
MsgBox("No New Record Found")
End If


End Function


End Class
Oct 15 '07 #1
3 1506
RedSon
5,000 Recognized Expert Expert
Moving from Programming challenges and IT case studies.
Oct 15 '07 #2
Plater
7,872 Recognized Expert Expert
What line of code is actually causing there exception to show?
And what other information is given about it? (There should be more, like "Connection refused" or "connection timeout" or something)
Oct 15 '07 #3
Shashi Sadasivan
1,435 Recognized Expert Top Contributor
Are you able to create an ODBC connection to MySql ?

Maybe you have not installed the MySql .net connector yet.

once you are done with that...have a look at the
connection strings

cheers
Oct 15 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

12
3589
by: Sarah Tanembaum | last post by:
Though I installed MySQL5 and PHP5, how come my phpinfo() shows as follow: MySQL Support enabled Active Persistent Links 0 Active Links 0 Client API version 3.23.57 <<<<<<<<<<<<<<< ...
0
1270
by: Centurion | last post by:
Hi All, Anyone know where I can get some more detailed info about the status of MySQL5 stored procedures support in PHP5? I can run the procedures without significant drama, but I don't get a...
0
1166
by: christian | last post by:
Hi know anybody a successfuel working gui which working with mysql5.0.2. I'm getting allways a crash with query-browser and others. many thanks & regards, christian
1
121507
by: jiing | last post by:
Now let me describe what I have done and my purpose: Originally, I want to user ports to install phpBB But I found that phpBB doesn't support mysql 5.x (but the ports installed mySQL 5.0.0...
4
2268
by: cieletmer | last post by:
Greetings! Does anyone have examples on how to interact with mysql5 stored procedures from php? I have a stored procedure sp_get_values() with last line SELECT v_computed_value1 AS cv1,...
0
1053
by: Zal | last post by:
have tried to follow the following instructions but to no success, hope someone can help me I have 2 servers server1 and server2. Server1 is the domain server, running sbs2003, i have gone to...
0
1353
by: ojorus | last post by:
Hi; I am using the mysqli-extension on all my database queries. Everything worked just fine when I used MySQL 4, but when the database was upgraded to MySQL 5 (5.0.22), I got a strange error....
3
5094
by: yogesh | last post by:
how to connect MySQL using C++ in redhat .... can any one tell a sample of code to creat ,connect and execute the statement in c++ code ... please help me .....
4
1449
by: opswordfish | last post by:
Hi I've visited a lot of forums regarding getting MySQL5 working with PHP5 in IIS and it seems that with MYSQL5 you need to use mysqli in PHP and that you need to uncomment the extension in...
0
7137
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7347
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7416
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
5656
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
5062
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
4732
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3218
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3207
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
443
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.