Tuesday, September 27, 2011

Connection Test Page in Asp.net

Following is a simple connection test page. At some point we need to test why the website is not working, so we can use this page. <%@ Page Language="C#" %> <%@ Import Namespace="System.Data" %>
<%@ Import Namespace="System.Data.SqlClient" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server">private void TestConnection() {
// Exampe of connection string server=DevSrv;packet size=4096;user id=test1;persist security info=True;initial catalog=Northwind;password=test2;" SqlConnection dbConnection = new SqlConnection("<Enter your connection string information here>"); // Example of sql statement SELECT COUNT(RegionID) IsPresent From Region
String sql="<Enter your sql statement here>";
int i =0; try {
SqlCommand cmd=new SqlCommand(sql,dbConnection); cmd.CommandType=CommandType.Text;i = (
int) (cmd.ExecuteScalar()); Response.Write("Connection Test was sucessfull");
catch(Exception ex) {
finally {
if (dbConnection.State == ConnectionState.Open) dbConnection.Close();

protected void Button1_Click(object sender, EventArgs e) {
</script> <html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Connection Test Page</title> </head>
<form id="form1" runat="server">
<asp:Button ID="Button1" runat="server" OnClick="Button1_Click" Text="Test Connection"
Width="251px" />

</form> </body>

No comments:

Post a Comment

Your project is not referencing the "MonoAndroid,Version=v8.1" framework. Add a reference to "MonoAndroid,Version=v8.1" in the "frameworks" section of your project.json, and then re-run NuGet restore.

I had  the same problem. Reason: file obj/project.assets.json target "MonoAndroid,Version=v7.1" when my project target androi...