No DSN access database
Any ASP script to access the database must first turn on the database on the server, we have two ways: Establish a connection via DSN. No DSN is established
A DSN connection requires a server-based system administrator to set a DSN with an ODBC tool in the control panel, or use a third-party server component, let your ASP script establish a DSN by modifying the registry when needed. I will provide A DSN build component for download.
A DSN connection typically requires: DSN name, user name, password, for example we use user name "student", password "magic", establish a connection via DSN "Student":
1. SET CONNTEMP = Server.createObject ("adoDb.connection") 2. ConnTemp.open "DSN = student; uid = student; PWD = MAGIC" 3. Set Rstemp = ConnTemp.execute ("Select * from authors")
If we don't have DSN, what should we do? But we know that the file name (for example, Access, Paradox, FoxPro database) or data source name (for example, SQLServer database). There is a method, we don't want DSN to access the database Note that you must know the actual file path! For example: "c: /tsserver/account17/nwind.mdb". Fortunately, method server.mappath can return the address on the server.
1. SET CONNTEMP = Server.createObject ("AdoDb.Connection") 2. Cnpath = "DBQ =" & Server.mappath ("YourTable.mdb") 3. ConnTemp.Open "Driver = {Microsoft Access Driver (* .mdb )}; "& cnpath4. set RSTEMP = ConnTemp.execute (" Select * from authors ")
'No DSN is established to connect DSNTEMP = "driver = {Microsoft Access Driver (* .mdb)};" DSNTEMP = DSNTEMP & "DBQ =" & Server.MAppath ("nwind.mdb") Conntemp.Open DSNTemp' does not have to establish a connection with DSN
SET RSTEMP = ConnTemp.execute ("Select * from customer '") HOWMANYFIELDS = RSTEMP.FIELDS.COUNT -1%>