ASP不用DSN如何与SQL数据库连接
编号:QA002203
建立日期: 1999年12月9日 最后修改日期:1999年12月9日
所属类别:
sandy:
操作系统:NT 4.0+IIS 4.0
编程工具:asp
问题:请问不用DSN如何与SQL数据库连接?
回答:
ASP编程是Web Server端的技术(OLEDB Provider 及 ODBC Drivers 均装在 Web Server 端),Web Server与 DataBase Server 是Client/Server的结构。用(Web Server端的)DSN(ODBC)连数据库要在建DSN时指定DataBase Server,即DSN包含了DataBase Server、ODBC Driver(数据库类型)、数据库。非DSN连数据库要在程序中指定DataBase Server、Driver(Provider)、数据库。总之本质都要指定DataBase Server:
<%
dim adoConnection
dim adoRecordset
Set adoConnection = Server.CreateObject("ADODB.Connection")
rem adoConnection.open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath ("/") & "\Data\NWind2K.mdb"
'使用Microsoft OLEDB Provider for ODBC Drivers + SQL Server (Ms SQL 的 ODBC Driver)两层接口:
adoConnection.Open "Data PROVIDER=MSDASQL.1;Driver=SQL Server;Server=playyuer;UID=sa;PWD=;Database=northwindcs"
'使用Microsoft OLEDB Provider for SQL Server (Ms SQL 的 OLEDB 专用Native接口)一层接口:
'adoConnection.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=northwindcs;Server=DBServerName;"
Set adoRecordset = Server.CreateObject("ADODB.Recordset")
adoRecordset.open "select 产品名称 as PName,产品.* from 产品",adoConnection
%>
此问题由于溪玥回答。
| |
|
|
| |
|
|