很多人一定用过Query Analyzer,这个工具的功能如何如何,就不用我说了,这次给大家介绍下Web下的Query Analyzer,界面如图1,使用ASP写的。
(图1)
源程序如下:
<%
dim conn
dim connstr
on error resume next
if request("selectdb")="mdb" then
if request("dbname")<>"" then
connstr="DBQ="+server.mappath(request("dbname"))+";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"
set conn=server.createobject("ADODB.CONNECTION")
if err.number<>0 then
err.clear
set conn=nothing
response.write "错误:数据库连接出错!"
else
if request("dbpass")<>"" then
conn.open connstr
else
Conn.Open connstr,"admin",request("dbpass")
end if
if err then
set conn=nothing
response.write "错误:数据库连接出错!!!<br>" + err.description
err.clear
end if
end if
end if
elseif request("selectdb")="mssql" then
if request("dbname")<>"" then
connstr = "Provider=SQLOLEDB.1"
connstr = connstr & ";Data Source=" & request("sqlip") 'sql_server数据库
connstr = connstr & ";User ID=" & request("sqladmin") '数据库服务器用户
connstr = connstr & ";Password=" & request("sqlpass") '登录口令
connstr = connstr & ";Initial Catalog=" & request("sqldb") '数据库名
set conn=server.createobject("ADODB.CONNECTION")
if err.number<>0 then
err.clear
set conn=nothing
response.write "错误:数据库连接出错!"
else
conn.open connstr
if err then
set conn=nothing
response.write "错误:数据库连接出错!!!<br>" + err.description
err.clear
end if
end if
end if
end if
sub endConnection()
conn.close
set conn=nothing
end sub
%>
<HTML>
<HEAD>
<TITLE>Query Analyzer</TITLE>
<STYLE type=text/css>BODY {FONT-FAMILY: "宋体", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}
P {FONT-FAMILY: "宋体", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}
BR {FONT-FAMILY: "宋体", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}
TD {FONT-FAMILY: "宋体", "Arial Narrow", "Times New Roman"; FONT-SIZE: 9pt}
.p9 {FONT-SIZE: 9pt; LINE-HEIGHT: 14pt}
A:link {COLOR: #004080; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt; TEXT-DECORATION: none}
A:visited {COLOR: #004080; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt; TEXT-DECORATION: none}
A:hover {COLOR: #ff0000; FONT-SIZE: 9pt; LINE-HEIGHT: 14pt; TEXT-DECORATION: underline}
.p105 {FONT-SIZE: 10.5pt}
INPUT.yellowbtn {BACKGROUND-COLOR: #88a3f2; COLOR: #000000; FONT-SIZE: 9pt}
</STYLE>
</HEAD>
<BODY BGCOLOR="#FFFFFF" topmargin="0">
<script language=JavaScript>
function setWB(x) {
document.main.whichbutton.value = x;
document.main.submit();
}
function showSQL(x) {
sqlvalue = document.main.sql.value;
if (x == 0) {
smsg = "\n怎样使用sql语句帮助:\n\n";
smsg = smsg + "1. 在选择框里选一个命令\n";
smsg = smsg + "2. 点击[显示]按钮\n";
smsg = smsg + "3. sql语句会显示在左边的文本框里面\n\n";
smsg = smsg + "4. 修改此语句来适合你数据库结构\n\n";
smsg = smsg + "5. 根据语句查询结果或执行命令\n\n";
alert(smsg); }
else if (x == 1) {
smsg = "SELECT columnName1, columnName2\n";
smsg = smsg + " FROM tableName\n";
smsg = smsg + " WHERE columnName = 'value'\n\n";
document.main.sql.value = smsg;
}
else if (x == 2) {
smsg = "INSERT INTO tableName\n";
smsg = smsg + " (columnName, IntegerColumnName)\n";
smsg = smsg + " VALUES (