当前位置: 代码迷 >> Sql Server >> asp连接整个SQL server数据库如何做
  详细解决方案

asp连接整个SQL server数据库如何做

热度:83   发布时间:2016-04-27 17:16:27.0
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_STRINGSET 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_STRINGSET 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 explicitdim startimedim conndim connstrdim db,pass_word,User_ID,Data_Sourcestartime=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 connstrfunction CloseDbConn.closeSet conn = NothingEnd 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版问连接字符串的写法
------解决方案--------------------
关注...
  相关解决方案