Groups > Databases > MySQL for ASP.NET > Re: Communicating with mySQL DB




Communicating with mySQL DB

Communicating with mySQL DB
Thu, 20 Mar 2008 07:56:21 +000
Hello

I have a simple web application (in Visual Studio 2005) that I wanted to test
how to connect and communicate with a mySQL DB through.

This aplication have the following file called (next.aspx), if you open this
file html source then all you will see is this:

 

1    <%@ Page Language="VB" AutoEventWireup="false"
CodeFile="next.aspx.vb" Inherits="_next" %><html>
2    <head>
3    <title>Hello</title>
4    </head>
5    <body>
6    <%  SayAgain()%></body>
7    </html>
  

In my next.aspx.vb you will find the following:

 

1    Imports System.Data.OleDb
2    Imports WebConfig = System.Configuration.ConfigurationManager
3    4    Partial Class _next
5    Inherits System.Web.UI.Page
6    Sub SayAgain()
7    Try
8                Dim MyLine As New Data.DataSet
9                MyLine = DB("select Comment from MyTable")
10               Response.Write(MyLine.Tables(0).Rows(0).Item(0))
11   Catch ex As Exception
12               Response.Write("Error: " + ex.Message)
13   End Try
14       End Sub15   16   'this function reads, writes, updates and deletes from
the current system database
17   Public Function DB(ByVal MyCommand As String, Optional ByVal
ConnectionString As String = "") As Data.DataSet
18   19   If ConnectionString = ""Then20              
ConnectionString = WebConfig.AppSettings("ConString")
21   End If
22   23           Try
24               Dim MyConnection As New OleDbConnection(ConnectionString)
25   Dim MyAdapter As New OleDbDataAdapter(MyCommand, MyConnection)
26   Dim MyDataSet As New Data.DataSet
27               MyAdapter.Fill(MyDataSet)
28   Return MyDataSet
29   Catch ex As Exception
30               Response.Write(ex.Message)
31   Return Nothing
32           End Try
33   34       End Function
35   36   End Class   

The WebConfig.AppSettings("ConString") is defined in the web.config
file as in the following:

  <appSettings>
    <add key="ConString" value="Provider=SQLOLEDB;
Driver={MySQL ODBC 3.51
Driver};Server=MY_DOMAIN;Port=3306;Database=SOME_DB;User=SOME_USER;
Password=SOME_PW;Option=3;" />
  </appSettings>
  

When I run this application, the following error message comes up:

Unable to communicate with target database: Invalid authorization specification
Invalid connection string attributeError: Object reference not set to an
instance of an object. 

My question is: Did I provide the wrong connection string to this kind of mySQL
server? I even tried several connection strings from
[http://www.connectionstrings.com/?carrier=mysql] but non worked. What am I
missing here?
Post Reply
Re: Communicating with mySQL DB
Fri, 21 Mar 2008 04:55:02 +000
Does the DB user have required authoritty to perform the task?r u able to
connect to MySql directly as a given user and password,u r specifying in
connection string?Also,check if the  'value' part of your appsettings ,is the
same as  what u see, in the properties window,when u right click against  ur
connection in server explorer

i am using ODBC connection to connect with MySQL ,though i am testing by
connecting as root user.. i don't specify the password in connection string...
Post Reply
about | contact