ASP创建SQL Server数据库的两种方法

Post by agang 2010-10-19 22:30 Tuesday

ASP创建SQL Server数据库的两种方法

方法一:

<%
' ************ 使用ADODB.Connect对象创建 ************************
Dim oConn
Dim sDatabaseName
sDatabaseName = "CodeCreateDB"
Set oConn = Server.CreateObject("ADODB.Connection")
oConn.Open "Provider=SQLOLEDB;Data Source=(local);User ID=sa;Password=;"
oConn.Execute "CREATE DATABASE " & sDatabaseName
%>

 

方法二:

<%@ Language=VBScript %>
<%
' ******************* 使用 SQLDMO Object 对象库 *******************
Dim oSQLServer
Dim oDatabase
Dim oDBFileData
Dim oLogFile
Dim sDatabaseName
Dim sDatapath

'数据库名字
sDatabaseName = "CodeCreateDBTest"
'数据文件保存路径
sDatapath = "D:\"

'创建Sql Server对象并进行链接,(local)处为Server名字
Set oSQLServer = Server.CreateObject("SQLDMO.SQLServer")
'  oSQLServer.LoginSecure = True       ' 使用集成验证integrated security
'  oSQLServer.Connect "(local)"
oSQLServer.Connect "(local)", "sa", "" ' 使用标准验证 standard security

' 创建Database对象
Set oDatabase =  Server.CreateObject("SQLDMO.Database")
oDatabase.Name = sDatabaseName

' 创建db文件对象
Set oDBFileData =  Server.CreateObject("SQLDMO.DBFile")
With oDBFileData
    .Name = sDatabaseName & "_data"
    .PhysicalName = sDatapath & "\" & sDatabaseName & "_data.mdf"
    .PrimaryFile = True
    .FileGrowthType = SQLDMOGrowth_MB
    .FileGrowth = 1
End With

' 创建日志文件对象
Set oLogFile =  Server.CreateObject("SQLDMO.LogFile")
With oLogFile
    .Name = sDatabaseName & "_log"
    .PhysicalName = sDatapath & "\" & sDatabaseName & "_log.ldf"
End With

'把DB文件对象和日志文件对象添加到DataBase数据库对象
oDatabase.FileGroups("PRIMARY").DBFiles.Add oDBFileData
oDatabase.TransactionLog.LogFiles.Add oLogFile

' 把数据库添加到Sql server(create the database)
oSQLServer.Databases.Add oDatabase

' 关闭连接
oSQLServer.Close

' 释放对象
Set oLogFile = Nothing
Set oDBFileData = Nothing
Set oDatabase = Nothing
Set oSQLServer = Nothing
%>

0

使用 Request.Form 集合之后,不能调用 BinaryRead。

Post by agang 2010-6-27 15:32 Sunday

request 对象 错误 'asp 0206 : 80004005'

不能调用 binaryread

/my/upload.inc,行 51

使用 request.form 集合之后,不能调用 binaryread。

upload.inc代码前的文件,和包含的文件不得含有request.form

/my/upload.inc

0

WAP网站简易统计系统 1.0

Post by agang 2010-6-20 10:08 Sunday


<%
 set conn=server.createobject("adodb.connection")
 conn.open "driver={microsoft access driver (*.mdb)};dbq=" & server.mappath("mydatabase/#visitcount.mdb")
 phoneaccept=request.servervariables("http_accept") '支持的文件类型
 phoneip = request.servervariables("remote_addr")        '客户端的ip地址 
 phonenumber=request.querystring("phonenumber") & request.servervariables("http_x_up_calling_line_id") & request.servervariables("deviceid")
 visitfile =request.servervariables("http_url")             '访问的文件路径
 phoneuseragent = request.servervariables("http_user_agent")
 if phoneip="218.12.56.224" then  ' or phoneip="211.94.69.240"
 ' iswriteindb="false"   '如果取到的为自己调试的ip地址,则不写入数据表。屏蔽此句,可以记录所有ip访问。
 end if
 'if instr(terminal,"m3gate")<>0 then '
 ' iswriteindb="false"   '开发人员用m3gate调试。
 'end if 
 if instr(phoneuseragent,"mozilla")<>0 then
 ' iswriteindb="false" '非手机和wap模拟器都不写入数据库
 end if
 if phoneip=session("phoneip") then  
 ' iswriteindb="false"   '不是每次访问都写入。防止重复写入较多同一地址
 end if
 ' session.timeout=30 '设置session的时间为60分钟。
 ' session("phoneip")=phoneip
%> 

<%
 'if iswriteindb<>"false" then
  strsql="insert into visitcount(phonenumber,phoneip,phoneuseragent,phoneaccept,visitfile) values (" & "'" & phonenumber & "','" & phoneip & "','" & phoneuseragent & "','" & phoneaccept & "','" & visitfile & "')"
  set rs=conn.execute(strsql)
 'end if
%>

0

清除asp缓存三个办法

Post by agang 2010-4-19 11:18 Monday

清除asp缓存三个办法
1、在asp页面首部加入
response.buffer = true
response.expiresabsolute = now() - 1
response.expires = 0
response.cachecontrol = "no-cache"
response.addheader "pragma", "no-cache"
或者将此代码写到一个包含文件包含到asp文件里

2、在html代码中加入
<head>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
</head>

3、在重新调用原页面的时候在给页面传一个参数
href="****.asp?random()"

0

ASP判断远程文件是否存在

Post by agang 2009-6-27 19:11 Saturday

<%
function testurl(url)
dim httpxml
set httpxml = createobject("msxml2.xmlhttp")
httpxml.open "head",url,false
httpxml.send
if httpxml.status = 200 then
testurl = 1
else
testurl = 0
end if
set httpxml = nothing
end function

这里的200表示是200即访问正常如果是404是的话则说明页面不存在呵

下面是实例
if testurl("http://www.goldtimes.net/lspic/price/01-19.rar")=0 then
response.redirect "http://www.nmi.cn"
else
response.redirect "http://www.hnyp.cn"
end if

%>

以上是方法一,我写了一个更简单的供大家参考使用

---------------------------------------------------------

set xmlhttp =server.createobject("microsoft.xmlhttp")
xmlhttp.open("head","http://www.nmi.cn/index.htm",false)
xmlhttp.send()
if xmlhttp.status=200 then
'文件存在
end if

0

ASP复制文件到其他文件夹下重新命名

Post by agang 2009-6-16 20:10 Tuesday

asp复制文件到其他文件夹下重新命名

 

<%on error resume next
dim fso,wj,path,filepath,foldername,newfilename,targetpath
wj="../index.html"
path="/wenjian/"
set fso=server.createobject("scripting.filesystemobject")
filepath=server.mappath(wj)'得到源文件路径
foldername=server.mappath(".")&path'得到新目录a路径
newfilename="other.html"'得到保存到a目录的新文件名
targetpath=foldername&""&newfilename'得到新文件完整路径
if fso.folderexists(foldername) then'判断a目录是否存在
fso.copyfile filepath,targetpath,true
else
fso.createfolder(foldername)'创建a目录
fso.copyfile filepath,targetpath,true
end if
set fso=nothing'释放内存
if err then
response.write err.description
end if
%>

0

asp 防盗链

Post by agang 2009-6-7 9:03 Sunday

<!--#include file="include/agang_sql.asp"-->
<!--#include file="conn.asp"-->
 <%
server_v1=cstr(request.servervariables("http_referer"))
server_v2=cstr(request.servervariables("server_name"))
if mid(server_v1,12,len(server_v2))<>server_v2 and mid(server_v1,8,len(server_v2))<>server_v2  then
response.write "<script language=javascript>alert('非法操作');history.back(-1)</script>"
response.end
end if
%>
<%
set rs=server.createobject("adodb.recordset")
sql="select download from shop_goods where id="&request("id")        
rs.open sql,conn,1,1
url=""&rs(0)&""
response.redirect "http://download.nmi.cn:8081/"&url
response.end
rs.close                              
set rs=nothing                              
conn.close                              
set conn=nothing%>

 

0

禁止站外提交的正确写法

Post by agang 2009-6-1 10:26 Monday

    
 <%
server_v1=cstr(request.servervariables("http_referer"))
server_v2=cstr(request.servervariables("server_name"))
if mid(server_v1,8,len(server_v2))<>server_v2 then
response.write "<script language=javascript>alert('error');history.back(-1)</script>"
response.end
end if
%>

 

这是网络上公布的代码,其实是很不完善的。

忽略了有www和没有www的情形。

 

正确的写法:

 

    
    
 <%
server_v1=cstr(request.servervariables("http_referer"))
server_v2=cstr(request.servervariables("server_name"))
if mid(server_v1,12,len(server_v2))<>server_v2 and mid(server_v1,8,len(server_v2))<>server_v2  then
response.write "<script language=javascript>alert('error');history.back(-1)</script>"
response.end
end if
%>

 

在以下网站中测试通过

 

http://www.pany.net.cn

 

http://pany.net.cn

 

http://hainan.hnyp.cn

0

让asp生成UTF-8格式

Post by agang 2009-4-20 8:57 Monday

这里set myfile = fso.createtextfile(xmlfile,true)
再加上一个参数值"true"就行了,就这样
set myfile = fso.createtextfile(xmlfile,true,true)

0

CInt与Int的区别

Post by agang 2009-4-3 8:37 Friday



cint 会进行四舍五入取最接近它的偶数,也就是说当小数部分为0.5xxxx时,它会取最接近x.5xx的偶数.

如 cint(0.5)=0 ; cint(1.5)=2 ; cint(2.5)=2 ;cint(3.5)=4

而int就是取整函数,会去除小数点部分.如 int(1.5)=1 ...

0