Database connection issue

Discussion in 'Databases' started by tlandsman, Sep 9, 2012.

  1. Hiu! I'm trying to figure out how to set up a database connection and can't seem to figure it out. I'm writing an Asp.net page. Can someone tell me what I'm doing wrong:


    <%@ Page Language="C#" Debug="true" %>
    <%@ Import Namespace="System.Data.SqlClient" %>
    <Script language = "c#" Runat="Server">


    void Page_Load(){
    string strResultsHolder;
    strResultsHolder="";

    SqlDataReader vDataReader;
    SqlConnection conPubs;
    SqlCommand cmdSelect;

    try
    {
    conPubs = new SqlConnection("server=s09.Winhost.com;database=DB_46795_database;uid=DB_46795_database_user;pwd=password");
    conPubs.Open();
    strResultsHolder = "Connection successful";

    conPubs.Close();


    }
    catch (Exception e)
    {
    strResultsHolder = "Connection failed";
    }



    //display results in divDisplay
    divDisplay.InnerHtml = strResultsHolder;


    }//end Page_Load
     
    Last edited by a moderator: Oct 14, 2015
  2. ComputerMan

    ComputerMan Winhost Staff

    Last edited by a moderator: Oct 14, 2015

Share This Page