日期:2014-05-18  浏览次数:20571 次

asp连接整个SQL server数据库怎么做?
asp开始是连接Access数据库的,现在我想把它改成连接sql server数据库,我改怎么改写代码?


set joekoe_cms=new class_joekoe_cms
'---------------------------------数据库连接字符串----------------------------------
joekoe_cms.connstr="DBQ="&server.mappath("data_jk/joekoe_data.asp")&";DRIVER={Microsoft Access Driver (*.mdb)};"

------解决方案--------------------
SQL code
asp衔接Mssql的办法及常见的差错
//第一种写法:
MM_conn_STRING = "Driver={SQL Server};server=(local);uid=sa;pwd=;database=infs;"
Set conn = Server.Createobject("ADODB.Connection")
conn.open MM_conn_STRING
SET RS=SERVER.CreateObject("ADOBD.recordset")
SQL="SELECT * FROM TABLE ORDER BY ID DESC"
RS.open SQL,CONN,3,3  
//第二种写法:(DSN衔接)
MM_conn_STRING="DSN=BBS;UID=SA;PWD=12345"
Set conn = Server.Createobject("ADODB.Connection")
conn.open MM_conn_STRING
SET RS=SERVER.CreateObject("ADOBD.recordset")
SQL="SELECT * FROM TABLE ORDER BY ID DESC"
RS.open SQL,CONN,3,3   // 3,3是改动、删除、增添开关!
//第三种写法:
MM_conn_STRING_own = "Driver={SQL Server};server=(local);uid=sa;pwd=11111;database=infs;"
Set conn = Server.Createobject("ADODB.Connection")
conn.open MM_conn_STRING_own
//第四种 - 这种方式用在ACCESS中
strconn = "DRIVER=Microsoft Access Driver (*.mdb);DBQ=" _
& Server.MapPath("asp.mdb")
set conn = server.createobject("adodb.connection")
conn.open strconn
实现方式一:
<%
dim conn 
set conn=server.createobject("ADODB.connection") 
conn.open "PROVIDER=SQLOLEDB;DATA SOURCE=(local);UID=用户名;PWD=密码;DATABASE=数据库" 
Set conn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={SQL Server};SERVER=(local);UID=用户名;PWD=密码;DATABASE=数据库"
conn.open DSNtemp
%>

实现方式二:
<%
option explicit
dim startime
dim conn
dim connstr
dim db,pass_word,User_ID,Data_Source
startime=timer()
db="数据库名称"
Pass_word="帐号密码"   
User_ID="登陆帐号"     
Data_Source="服务名称或者ip"   
Set conn = Server.CreateObject("ADODB.Connection")
connStr="Provider=SQLOLEDB.1;Password='"&pass_word&"';Persist Security Info=True;User ID='"&User_ID&"';Initial Catalog='"&db&"';Data Source='"&Data_Source&"'" 
conn.Open connstr
function CloseDb
Conn.close
Set conn = Nothing
End Function

常见故障

(a)
Microsoft OLE DB Provider for ODBC Drivers 过错 '80040e57' 
[Microsoft][ODBC SQL Server Driver][SQL Server]String or binary data would be truncated.

这是由于数据库表中字段的字节数太小了。

(b)
出错提醒:
Microsoft OLE DB Provider for ODBC Drivers 过错 '80040e57' 

[Microsoft][ODBC SQL Server Driver][SQL Server]Arithmetic 

overflow error for data type smallint, value = 32768. 
是由于字段的类型是smallint太小了应改成int.

(c)
icrosoft OLE DB Provider for ODBC Drivers 过错 '80040e4d' 

[Microsoft][ODBC SQL Server Driver][SQL Server]Login failed for user 'user78'. 

/index333.asp,行30
数据库的用户名或密码不对.

(d)
Microsoft OLE DB Provider for ODBC Drivers 差错 '80004005' 

[Microsoft][ODBC 驱动程序 管理器] 未发明数据源名称并且未指定默认驱动程序 

/include/conn.asp,行3 
这种现象的原由是:1.web服务器没有准确设置数据源,
须要您提供主机名和数据库IP地址,发信件到LIVEPERSON ,为您在服务器上树立数据源,方能正常调用。

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/fredrickhu/archive/2009/09/20/4573228.aspx

------解决方案--------------------
去ASP版问连接字符串的写法
------解决方案--------------------
关注...