locked
Best way to connect to SQL database RRS feed

  • Question

  • User1733586255 posted

    Hi, 

    I just want to know what is the difference and what is a good practice of connecting to database:

    1. Using ASP.NET Expression:

    <asp:SqlDataSource ID="SqlDataSource2" runat="server" ConnectionString="<%$ ConnectionStrings:Weekly_QAConnectionString %>" SelectCommand="SELECT * FROM [tbl_tests]"></asp:SqlDataSource>

    or

    2. sqlconnection:

     Try
                myConnection.Open()
    
                Dim myCommand As New SqlCommand(mySelectQuery, myConnection)
    
                myConnection.Close()
    
    Catch Ex As Exception
                myConnection.Close()
    End Try


    The former is very easy to write, visual studio creates ir automatically.

    Monday, October 7, 2013 8:12 AM

Answers

All replies