Click to See Complete Forum and Search --> : ASP access to DBMS


Crazy
01-06-2003, 02:56 PM
Hi guys,

I recently found a host that offers SQL Server as part of their hosting deal, but they state that you can only access it via ASP scripts, and not by using ODBC, OLEDB etc. Does ASP have its own connective technology?

I have used ASP but I have always used either ODBC or OLEDB for backend connection, so their response seems a bit odd to me. So, does anyone know how it is possible to access a backend DBMS using ASP scripts exclusively?

Cheers

vishu_gupt
01-06-2003, 11:45 PM
HI,
May be what they want to say that you can not connect the DB using DSN(User,file or system). you have to connect the DB using DSN less connection and using native interfaces in ASP. Here is a sample code. Try this out:
--------------------------------------
<% ' to integrate/test this code replace the
' Data Source value in the Connection string%>
<%
' connection and recordset variables
Dim Cnxn, strCnxn
Dim rsCustomers, strSQLCustomers
Dim rsProducts, strSQLProducts

' open connection
Set Cnxn = Server.CreateObject("ADODB.Connection")
strCnxn = "Provider='sqloledb';Data Source=" & _
Request.ServerVariables("SERVER_NAME") & ";" & _
"Integrated Security='SSPI';Initial Catalog='Northwind';"

Cnxn.Open strCnxn

' create and open first Recordset using Connection - execute
Set rsCustomers = Server.CreateObject("ADODB.Recordset")
strSQLCustomers = "SELECT CompanyName, ContactName, City FROM Customers"
Set rsCustomers = Cnxn.Execute(strSQLCustomers)

' create and open second Recordset using recordset - open
Set rsProducts = Server.CreateObject("ADODB.Recordset")
strSQLProducts = "SELECT ProductName, UnitPrice FROM Products"
rsProducts.Open strSQLProducts, Cnxn, adOpenDynamic, adLockPessimistic, adCmdText
%>
----------------------------