Open Sql connection ( : SqlConnection « Database « ASP.Net

Open Sql connection (

  <%@ import Namespace="System.Data" %>
<%@ import Namespace="System.Data.SqlClient" %>

<script language="VB" runat="server">
  Sub Page_Load()
   ' Dim strConnection as String = "user id=sa;password=;"
    'strConnection += "database=northwind;server=EWANB;"
    'strConnection += "Connect Timeout=30"
    Dim strConnection as String = "Data;Initial Catalog=DB_49907;User ID=java2suser;Password=password;"
    data_src.text = strConnection

    Dim objConnection as New SqlConnection(strConnection)

      con_open.text="Connection opened successfully.<br />"
      con_close.text="Connection closed.<br />"
    catch e as Exception
      con_open.text="Connection failed to open.<br />"
    end try
  end Sub

  <h4>Testing the data connection 
  <asp:label id="data_src" runat="server"/></h4>
  <asp:label id="con_open" runat="server"/><br />
  <asp:label id="con_close" runat="server"/><br />


Related examples in the same category

1.Catch data binding exception (
2.Use Trace to debug (
3.Display of Data in a Table (Grid) Using SQL Objects (
4.Setup SqlConnection (C#)