asp连接Mssql的方法及常见的错误

  • Post author:
  • Post category:其他


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 ,为您在服务器上树立数据源,方能正常调用。



版权声明:本文为fredrickhu原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。