You are Here:
FAQ
Scripting and Programming Languages
MS SQL Database
Article #6
|
How to make a connection to Microsoft SQL Database using ASP scriptFirst 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 Microsoft SQL Database? to get the above information. Following is an example ASP script to connect to the database and query a table.
<html>
<title>Queries from the MS-SQL database with ASP</title>
<body bgcolor="FFFFFF">
<h2>Query from table <b>products</b> with ASP</h2>
<%
Set conn = Server.CreateObject("ADODB.Connection")
conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=mssqxxx.1and1.com;UID=dboxxxxxxxxx;PWD=xxxxxxxx;DATABASE=dbxxxxxxxxx"
'This code block will create a recordset
Set rs = Server.CreateObject("ADODB.Recordset")
SQL = "select * from products"
rs.open SQL, conn
'will iterate to display the records got from the database
While Not rs.EOF
response.write(rs("id") & " " & rs("price"))
rs.MoveNext
Wend
'closes the connection
rs.close
conn.close
Set rs = Nothing
Set conn = Nothing
%>
</body>
</html>
DATA SOURCE is the hostname.UID is the user name PWD is the password DATABASE is the database name IMPORTANT – NOTE! Memory resources on the server will only be released with the corresponding directives: rs.close, conn.close, Set rs = Nothing, Set conn = Nothing Access to Microsoft SQL databases is only via ASP scripts. The database servers cannot be directly accessed through the Internet for safety reasons. Please note that under no circumstances may the database be used for log evaluation processes (e.g. ivw), add-clicks, chat systems, banner rotations or any other applications that put high loads on the database. Disclaimer: 1&1 provides the scripts and related information on this page as a courtesy, subject to 1&1's General Terms and Conditions of Service (the "GT&C"). As set forth in more detail in the GT&C, the scripts and information are provided "as-is", without any warranty, and 1&1 is not liable for any damages resulting from your use of the scripts or information. |
© 2008 1&1 Internet Inc - About 1&1 Internet