Connection testing MySQL


This article explains how to test and use the database connection. We give the example code to test this, the only thing you need to change is the data in the web.config.
This should contain your own data such as your database and password.

You can create the following 2 files within the filemanager or FTP:

Default.aspxDefault

.aspx.cs


If all goes well you already have the file web.config in the wwwroot, if not then you can also add this.


-------------------------------------------------------------------------------------------------------------------------Default.aspx code:

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %> <

; !DOCTYPEhtml>; <

; html xmlns= "https://www.w3.org/1999/xhtml"> <
; head runat=" server"> <;title><
;/title> </head&
gt;
<body><
form id="form1" runat=" server">;<div>; <

;


/div>








</form><
/body> </html>

-------------------------------------------------------------------------------------------------------------------------De















code voor Default.

aspx.csusing

System;
using System.Collections.Generic;
using

System.Configuration;
using

System.Linq;
using

MySQL.Data.MySqlClient;
using System.Web;
using

System.Web.UI;
using

System.Web.UI.WebControls;
using

System.Data;

public partial class_Default : Page {
protected void Page_Load(object sender, EventArgs e) {
string connStr = ConfigurationManager.ConnectionStrings["sqlConn"].ConnectionString;
MySqlConnection conn = new MySqlConnection(connStr);

try{
conn.Open();
if(conn != null && conn. State == ConnectionState . Open){
Response
. Write("The connection is open");
} elseif(conn == null || conn.

State == ConnectionState.Closed){
Response.Write("The connection is closed");
}

conn.Close();
conn = null;

if(conn != null && conn. State == ConnectionState . Open){
Response



.



Write("The connection is open");
} elseif(conn == null || conn.State == ConnectionState.Closed){
Response.Write("The connection is closed");

} }catch(MySqlException ex){
Response.





Write(ex.Message);
































































































}














































































}



































































-------------------------------------------------------------------------------------------------------------------------The









code for the web.config:

<?xml version="1.0"?> <
; configuration> <;
connectionStrings> <add name="sqlConn
" connectionString="Server=DatabaseHost ;Database=DatabaseName;Uid=DatabaseUser;Pwd=DatabasePassword;"/> </connectionStrings>;
< ;system.
web>; <
; compilation debug=" true" targetFramework= "4.5"/>; <;httpRuntime
targetFramework= "4.5"/> <

;

/system.web>
</configuration>;





































Possible hosts are mysql1.mijnhostingpartner.nl up to and including mysql11.mijnhostingpartner.nl. Which one you need exactly can be found in the control panel. The rest of the data can be determined in the control panel, when you can not connect through the script you can change the password within the control panel.
The password can be generated with the password generator.

After this has been done, you have the following files in your wwwroot:

Connection testing MySQL


In order to connect to MySQL, you also need the DLL which you place in the Bin directory. You can download this DLL here. If your connection is successful, the following message will be displayed when you go to the page in your browser.

The connection is openThe connection is closed









If you have any further questions you can always see if there is someone on the online chat.
Or you can create a ticket for this in the customer panel.

Keywords: connection testing MySQL mysql connecting