Brinkster Knowledge Base
How do I connect to a MS SQL database with ASP.NET 2.0
IMPORTANT: Be sure to make note of the following when using these coding examples:
1. Replace username with your Brinkster hosting account username.
2. Replace password with the password for the email account used above.
3. Please log into your account, select the web site settings, and use the correct server hostname.
SQL Server Database
<% Dim sqlConn As Data.SqlClient.SqlConnection = New Data.SqlClient.SqlConnection Dim connString As String = "Data Source=host.domain.com; & _ Initial Catalog=username; & _ Persist Security Info=True; & _ User ID=username;Password=password" Dim sSQL As String = "select * from tablename" Dim oDR1 As Data.SqlClient.SqlDataReader = Nothing sqlConn = New Data.SqlClient.SqlConnection sqlConn.ConnectionString = connString sqlConn.Open() Dim comm As Data.SqlClient.SqlCommand = New Data.SqlClient.SqlCommand(sSQL, sqlConn) Try oDR1 = comm.ExecuteReader If oDR1.HasRows Then While oDR1.Read ˜handle data End While End If Catch ex As Exception ˜handle exception Finally If Not oDR1 Is Nothing Then oDR1.Close() sqlConn.Close() End Try %> |