Solution:
Default.aspx
<asp:Label ID="lblMessage" runat="server"></asp:Label>
In the Default.aspx.cs file, add the following code in the Page_Load event:
protected void Page_Load(object sender, EventArgs e)
{
string connectionString = "Data Source=myServerAddress;Initial Catalog=master;User ID=myUsername;Password=myPassword;";
SqlConnection connection = new SqlConnection(connectionString);
try
{
connection.Open();
lblMessage.Text = "Connection has been established";
}
catch (Exception ex)
{
lblMessage.Text = "Error: " + ex.Message;
}
finally
{
connection.Close();
}
}
0 Comments