日期:2014-05-19  浏览次数:20398 次

asp连接远程sql
公司网站做好了,要上传到网上,以前我用是access,现在空间是用sql的,下面这些代码该怎么改。。。请对sal数据库驱动中那些参数给个说明
<%
set   conn=server.createobject( "adodb.connection ")
conn.open   "provider=microsoft.jet.oledb.4.0;data   source= "&   server.mappath( "\bondrise\database\admin.mdb ")

%>
  <%  
set   rs=server.createobject( "ADODB.Recordset ")  
sql= "select   top   10   *   from   news   order   by   id   desc "  
rs.open   sql,conn,1,1
do   while   not   rs.eof
response.write " <a   href= 'newcenter.asp?id= "   &   rs( "id ")   &   " '   target= '_blank '> "   &   rs     ( "content ")   &   " </a> <br/> ------------------------------------------------ <br/> "

rs.movenext
loop        
%>



------解决方案--------------------
<%
'----------------------
strSQLServerName = "218.244.136.24 " ' 这个地方可以写服务器名或ip地址
strSQLDBUserName = "sa " ' 数据库的登陆名,如果给你的用户名是sa
strSQLDBPassword = "sa的密码 "
strSQLDBName = "你的数据库名 "
'----------------------

'---------这个地方不用管,下面的是调用上面的变量连接数据库的-----
Set conn = Server.CreateObject( "ADODB.Connection ")
connstr = "Provider=SQLOLEDB.1;Persist Security Info=False;Server= " & strSQLServerName & ";User ID= " & strSQLDBUserName & ";Password= " & strSQLDBPassword & ";Database= " & strSQLDBName & "; "
conn.Open connstr
'---------
%>