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
Try reading our knowledge base article on How to query an SQL database with .NET SQL Data Provider in ASP.NET If that doesn't help you resolve your issue. Can you provide us with the error message you are getting on your end? Can you also tell us if you are doing this locally on your computer or on our web server?