You are Here: FAQ ->Scripting & Programming->MSSQL->Article #4


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


How to query the MS SQL database using ASP .net




ASP.net is supported only in Developer MS Package and Windows Server Package
First get the following information from your 1&1 Control Panel under
Applications -> MS SQL Administration.
Database Name
User Name
Host Name
Password
Follow the FAQ: Where can I find the necessary information to
connect to MS SQL Database?
to get the above information.

Following is an example script to connect to the database and query a table.
<%@ 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=mssqlxxx.1and1.com; initial catalog=dbxxxxxxxxx;uid=dboxxxxxxxxx;pwd=xxxxxxxx")
			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("id") & ", " & oDR.Item("price"))
	    		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>
server is the hostname.
initial catalog is the database name
uid is the user name
pwd is the password


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