Skip to content

Cookie settings

Choose which kinds of cookies you allow. You can change your choice at any time via Cookie settings at the bottom of every page. Privacy statement

Necessary

Always on

Needed to log in, keep your cart and remember your choices. These are always on.

Which cookies?
  • weboke_sessie, weboke_klant, weboke_remember: your session and staying logged in
  • weboke_basket: your cart
  • wkBtwIncl: showing prices with or without VAT
  • wok_cookies: your cookie choice, 12 months

Measures which ad leads to a visit or order, so we do not pay for ads that do nothing.

Which cookies?
  • Google Ads via Google Tag Manager (_gcl_au, _gcl_aw), up to 90 days
  • OpenAI Ads, ads in ChatGPT
  • wok_aff: which partner referred you to us (affiliate programme), 60 days

4.6

Connecting to a MySQL database from an ASPX page

If you want to connect to a MySQL database from an ASPX page, the text below may be useful for first making a simple test connection before starting your own project.

As an example, the .NET Connector 6.0 has been installed. You need to place the file Mysql.Data.dll in your root directory (httpdocs/bin). Otherwise you will get this message when testing: Compiler Error Message: BC30002: Type 'MySqlConnection' is not defined.

Make sure that your web.config contains at least these settings, otherwise no error messages will be shown:
<configuration>
<system.web>
<customErrors mode="Off"/>
</system.web>
</configuration>

You can download the file Mysql.Data.dll from the link below. Choose download Windows Binaries, no installer (ZIP), copy the file out of it manually and place it in the bin directory mentioned earlier:
http://dev.mysql.com/downloads/connector/net

Next, create the file test_mysql.aspx in httpdocs with this content (replace test64user with your own database user, and also change the password and database in the string to your own values):
<%@ 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 MySqlConnection
Dim myDataAdapter As MySqlDataAdapter
Dim myDataSet As DataSet

Dim strSQL As String
Dim iRecordCount As Integer

myConnection = New MySqlConnection("server=localhost; user id=test64user; password=testing; database=webawere_test64db; pooling=false;")

strSQL = "SELECT * FROM testtabel;"

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

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>

As a test, we created a small MySQL database containing 2 records:
CREATE TABLE `webawere_test64db`.`testtabel` (
`id` SMALLINT NOT NULL AUTO_INCREMENT ,
`veld1` VARCHAR( 30 ) NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = InnoDB

INSERT INTO `webawere_test64db`.`testtabel` (
`id` ,
`veld1`
)
VALUES (
NULL , 'Waarde1'
), (
NULL , 'Waarde2'
);

Was this article helpful?

← Back to General hosting

One moment…

Set up your domains

For each domain, arrange the nameservers, the link to your hosting and who becomes the owner.

Loading your domains…