For asp I use this:
I keep the MySQL connection string in an include file. Here is part of it:
 
<!-- #INCLUDE file="adovbs.inc" -->
<%
function ConnectDB() 
    dim masdataconn, strConnection
    ' open connection
    Set masdataconn = Server.CreateObject("ADODB.Connection")
    strConnection = "DRIVER={MySQL ODBC 3.51 Driver}; SERVER=myserver.com;
DATABASE=TestDataBase; USER=mysqlusername; PASSWORD=mysqlpassword;
OPTION=3;"
    masdataconn.Open strConnection
    set ConnectDB = masdataconn
end function
 
For ASP.NET:
You need to install the .Net package from the MySQL website.
Then include the package (DLL) as a reference.
This ends up in web.config:
<compilation debug="true">

<assemblies>

<add assembly="MySql.Data, Version=1.0.5.13785, Culture=neutral,
PublicKeyToken=C5687FC88969C44D"/>

</assemblies>

</compilation>

 

Code files looks like this:

Imports MySql.Data.MySqlClient

Public Shared Function ConnectDB(Optional ByVal destination As String =
"defaultdatabase") As MySqlConnection

Dim connStr As String

Dim masconn As MySqlConnection

If destination = "" Then destination = "lifesaver"

connStr = "server=myserver.com;user id=mysqlusername; password=mysqlpass;
database=" & destination & "; port=3030; pooling=false"

Try

masconn = New MySqlConnection(connStr)

masconn.Open()

Catch ex As MySqlException

''Return "Error connecting to the server: " + ex.Message

End Try

Return masconn

End Function

 

-----Original Message-----
From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of cahide26
Sent: Sunday, October 23, 2005 1:35 PM
To: [email protected]
Subject: [AspNetAnyQuestionIsOk] asp and mysql


Hi,

I am a asp-beginner and i am trying to connect mysql database via my
asp file but i cann't. I have installed mysql 4.1 and connector/odbc
3.51 .

i have tryed with two file one normal asp and another an asp.net

asp-file:
<html>
<!-- #INCLUDE file="dbKurf.inc" -->
<%
set adoConn = Server.CreateObject("ADODB.Connection")
'adoConn.Open "Driver="&dbDriver&"; Database="&dbDatabase&";
Uid="&dbUser&"; Pwd="&dbPass&";"

adoConn.Open "Driver={mySQL}; Server=localhost; Port=3306; Option=0;
Socket=; Stmt=; Database=kurf; Uid=root; Pwd=rishakawwemana;"
set adoRS = Server.CreateObject("ADODB.Recordset")
adoRS.ActiveConnection = adoConn

if adoConn.errors.count = 0 then
   response.write "<h2>Fields In The 'diwan' Table:</h2>"
else
   response.write "not connected"
end if

%>
</html>

when i drive http://localhost/mytest.asp  i got following error:
Error Type:
Microsoft OLE DB Provider for ODBC Drivers (0x80004005)
[Microsoft][ODBC Driver Manager] Data source name not found and no
default driver specified
/databas/kurfTest.asp, line 7
------------------------------------------

and here is my asp.net file:
MySQL.aspx

<%@ Page Language="VB" debug="true" %>
<%@ Import Namespace = "System.Data" %>
<%@ Import Namespace = "MySql.Data.MySqlClient" %>
<script language="VB" runat="server">

Sub Page_Load(sender As Object, e As EventArgs)

    Dim myConnection  As myodbc
    Dim myDataAdapter As MySqlDataAdapter
    Dim myDataSet     As DataSet

    Dim strSQL        As String
    Dim iRecordCount  As Integer

    myConnection = New MySqlConnection("server=localhost; user
id=root; password=rishakawwemana; database=kurf; pooling=false;")

    strSQL = "SELECT * FROM mytable;"

    myDataAdapter = New MySqlDataAdapter(strSQL, myConnection)
    myDataSet = New Dataset()
    myDataAdapter.Fill(myDataSet, "mytable")

    MySQLDataGrid.DataSource = myDataSet
    MySQLDataGrid.DataBind()

End Sub
</script>

<html>
<head>
<title>Simple MySQL Database Query</title>
</head>
<body>
<form runat="server">
<asp:DataGrid id="MySQLDataGrid" runat="server" />
</form>
</body>
</html>

in this case i got following error:
Compiler Error Message: BC30002: Type 'myodbc' is not defined.


thank you so much for your help.

my mail: [EMAIL PROTECTED]









SPONSORED LINKS 
Basic
<http://groups.yahoo.com/gads?t=ms&k=Basic+programming+language&w1=Basic+pro
gramming+language&w2=Computer+programming+languages&w3=Programming+languages
&w4=Java+programming+language&c=4&s=126&.sig=bnac3LCZpttb3c9FvbVU-A>
programming language    Computer
<http://groups.yahoo.com/gads?t=ms&k=Computer+programming+languages&w1=Basic
+programming+language&w2=Computer+programming+languages&w3=Programming+langu
ages&w4=Java+programming+language&c=4&s=126&.sig=1Czd2hKCO9_u4KVZQperFQ>
programming languages   Programming
<http://groups.yahoo.com/gads?t=ms&k=Programming+languages&w1=Basic+programm
ing+language&w2=Computer+programming+languages&w3=Programming+languages&w4=J
ava+programming+language&c=4&s=126&.sig=TyHGCjod4YOKITrSq1xccQ> languages

Java
<http://groups.yahoo.com/gads?t=ms&k=Java+programming+language&w1=Basic+prog
ramming+language&w2=Computer+programming+languages&w3=Programming+languages&
w4=Java+programming+language&c=4&s=126&.sig=PZAexF9LyXpKb3HDJSlB1g>
programming language    

  _____  

YAHOO! GROUPS LINKS 


        
*        Visit your group "AspNetAnyQuestionIsOk
<http://groups.yahoo.com/group/AspNetAnyQuestionIsOk> " on the web.
  

*        To unsubscribe from this group, send an email to:
 [EMAIL PROTECTED]
<mailto:[EMAIL PROTECTED]
e> 
  

*        Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service
<http://docs.yahoo.com/info/terms/> . 


  _____  




[Non-text portions of this message have been removed]



------------------------ Yahoo! Groups Sponsor --------------------~--> 
Get Bzzzy! (real tools to help you find a job). Welcome to the Sweet Life.
http://us.click.yahoo.com/A77XvD/vlQLAA/TtwFAA/saFolB/TM
--------------------------------------------------------------------~-> 

 
Yahoo! Groups Links

<*> To visit your group on the web, go to:
    http://groups.yahoo.com/group/AspNetAnyQuestionIsOk/

<*> To unsubscribe from this group, send an email to:
    [EMAIL PROTECTED]

<*> Your use of Yahoo! Groups is subject to:
    http://docs.yahoo.com/info/terms/
 


Reply via email to