Click to See Complete Forum and Search --> : "Embed" a data source (NOT using dsn)


IxxI
08-04-2004, 09:49 AM
I'm wondering if its possible to "embed" an sql data source in an asp page. What I mean by this is at the moment I'm connecting to the data source using:


strDBConn = "dsn=mydatabase;uid=sql;pwd=mydatabasepassword"

Set objConn = CreateObject("ADODB.Connection")
objConn.Open strDBConn


and I'm wondering if instead of this I can just connect to it using the databases name instead of dsn e.g. connecting to mydatabase1.dbo where that is the name of my database.

Sorry for the confusing explanation, hope it makes enough sense for a reply ;).
IxxI

schizo
08-04-2004, 11:26 AM
Here is a list of DNS-less connection methods for a variety of databases:

http://www.able-consulting.com/MDAC/ADO/Connection/ODBC_DSNLess.htm

buntine
08-04-2004, 11:48 AM
MS provide the MS Access Driver, which is a very basic data driver.

Dim objConn, strConn
Dim objRS, strQuery

'| Instantiate the object; create room for it in memory.
objConn = Server.CreateObject("ADODB.Connection")

'| Create the connection string.
strConn = "DBQ=" & Server.MapPath("dir/db_name.mdb") & ";" & _
"Driver={Microsoft Access Driver (*.mdb)}"

'| Open the connection. Pass the connection string.
objConn.Open(strConn)

'| Instantiate an ADO recordSet object, which will hold the records in a collection.
objRS = Server.CreateObject("ADODB.RecordSet")

'| Create an SQL query.
strQuery = "SELECT * FROM table_name"

'| Execute the SQL query and open the recordSet object. Pass the Connection object along with any ADO constants.
objRS.Open(strQuery), objConn, 3

Regards,
Andrew Buntine.