[VB.Net ASPX] SQL Connection String

aronquiray

Member
Reputation
0
On the Web.Config File add this
Code:
<appSettings>
		<add key="Variable1" value="Server=computername\sqlname;Database=Account;User ID=sa;Password=yourpassword" />
    	</appSettings>

On the Code itself

Code:
    Dim cn As SqlConnection
    Dim com As SqlCommand
    Dim dr As SqlDataReader
    Dim strcon As String
    Dim strqry As String



Try 
 strcon = System.Configuration.ConfigurationManager.AppSettings("Variable1).ToString()
                strqry = "You SQL QUERY HERE"
                cn = New SqlConnection(strcon)
                cn.Open()
                com = New SqlCommand(strqry, cn)
                dr = com.ExecuteReader

   If dr.Read < 0 then
    (TRUE CONDITION HERE)
   Else
    (FALSE CONDITION HERE)
END IF

                cn.Close()
                dr.Close()
                com.Dispose()

 Catch ex As Exception
Response.write("You Error Message Here")  or use LABELERROR.Text("MESSAGE") (mostly "Internal Server Error")

            End Try
 
Cookies are required to use this site. You must accept them to continue using the site. Learn more…