Connecting to a ms-access database using a DSN

Problem:

Connecting to a ms-access database using a DSN



Solution:

Using an ODBC DSN (Data Source Name) is a two step process.
 
1) You must first create the DSN.
2) Then use the following connection string - with your own DSN 
    name of course :
 
01. <% 
02. Dim objConn as ADODB.Connection
03. Dim objRS as ADODB.Recordset
04. Dim strConn as String
05. Dim strSQL as String
06. Set objConn = New ADODB.Connection
07. Set objRS = New ADODB.Recordset
08. strConn = "DSN=yourdsnname;Uid=databaseusername;Pwd=password;"
09. objConn.Open strConn
10. strSQL = "Select * from tbAddresses "
11. objRS.Open strSQL, objConn
12. %>
 
 
Exaplanation According to Line:
 
01. Open ASP tag
02. Declare a ADODB.Connection type variable
03. Declare a ADODB.Recordset type variable
04. Declare a String type variable
05. Declare a String type variable
06. Set new instance for ADODB.Connection
07. Set new instance for ADODB.Recordset
08. Set connection string into strConn
09. Open connection using strConn
10. Set query statement
11. Query from database
12. Close ASP tag
 
  • 0 Usuários acharam útil
Esta resposta lhe foi útil?

Artigos Relacionados

error:Microsoft OLE DB Provider for ODBC Drivers error '80040e37'

Problem: error:Microsoft OLE DB Provider for ODBC Drivers error '80040e37' Solution:...

error:Microsoft OLE DB Provider for ODBC Drivers error '80004005'

Problem: error:Microsoft OLE DB Provider for ODBC Drivers error '80004005' Solution:...

Error:Microsoft OLE DB Provider for ODBC Drivers Error '80004005' -- DSN Not Found...

Problem: Error:Microsoft OLE DB Provider for ODBC Drivers Error '80004005' -- DSN Not Found......

error:Why do I get the error 8000045 when running my MS Access scripts?

Problem: error:Why do I get the error 8000045 when running my MS Access scripts? Solution:...