You are Here: FAQ ->Scripting & Programming->ASP .Net->Article #2


WebHosting Microsoft-Edition This Article is for 1&1 Microsoft Web Hosting Only.


ASP.Net Database Connection String



<%@ Page Language="VB" %>
<script runat="server">
    
    Sub Page_Data
    	Dim oDR as System.Data.SQLClient.SQLDataReader
        Dim oCom As System.Data.SQLClient.SqlCommand
        Dim oConn as System.Data.SQLClient.SQLConnection
        try
            oConn = New System.Data.SQLClient.SQLConnection ("server=kundenmssql3.schlund.de; initial catalog=Northwind;uid=USERNAME;pwd=PASSWORD")
			oConn.Open()
			oCom = New System.Data.SQLClient.SqlCommand()
			oCom.Connection = oConn
			oCom.CommandText = "SELECT * FROM products"
			oDR = oCom.ExecuteReader()
			While oDR.Read
	    		Response.Write(oDR.Item("ProductName") & ", " & oDR.Item("UnitPrice") & "£")
	    		Response.Write("<BR/>")
    		End While
        catch
            Response.Write("Error:" & err.Description)
        Finally
        	oDR = Nothing
        	oCom = Nothing
        	oConn.Close()
        	oConn = Nothing
        end try
    End Sub

</script>
<html>
<title>Queries from the MS-SQL database with ASP</title>
<body bgcolor="FFFFFF">
<h2>Query from table <b>products</b> with ASP.NET</h2>
<%Page_Data()%>
</body>
</html>


Print Article
How useful was this article?
(From 5 = Very Useful to 1 = Not Very Useful at all):
1 2 3 4 5