Categories
Connection testing for MS-SQL
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 you can also add it. If you want to restore the web.config you can do this in the following way: restore web.config-------------------------------------------------------------------------------------------------------------------------Default
.aspx code:
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
DOCTYPEhtml>
xmlns= "https://www.w3.org/1999/xhtml">
runat= "server">
< title>
-------------------------------------------------------------------------------------------------------------------------The code for Default.
aspx.csusing
System;
using System.Collections.Generic;
using
System.Configuration;
using
System.Linq;
using System
.Data.SqlClient;
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;
SqlConnection conn = new SqlConnection(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(SqlException ex){
Response.
Write(ex.Message);
}
}
}
-------------------------------------------------------------------------------------------------------------------------The
code for the web.config:
xml version="1.0"?>
SQL 2008 | sql3.myhostingpartner.com |
SQL 2012 | sql8.myhostingpartner.com |
SQL 2014 | sql2014-1.myhostingpartner.com |
The rest you can determine in the control panel, if you can not connect via the script then you can change the password within the control panel.
The password can be generated with the password generator.
After this has been changed you have the following files in your wwwroot:
If your connection is successful the following message will be shown 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 MS_SQL mssql create connection