主题:各种数库连接的驱动
<% '与SQL的数库连接并打开数库
dim cn,rs,sql
set cn=server.createObject("ADODB.Connection")
cn.open "driver={sql server};server=WTW;database=asptest;"&"UID=sa;PWD=admin"
set rs=server.createObject("ADODB.recordset")
rs.open "select * from stu",cn
%>
--------------------------------------
<% '与Access的数库连接并打开数库
Set conn = Server.CreateObject("ADODB.Connection")
connstr="driver={Microsoft Access Driver (*.mdb)};pwd=gws;dbq=" & Server.MapPath("gws.mdb")
conn.open connstr
%>
----------------------------------
C#与(Access ,Excel连接)
using System.Data;
using System.Data.OleDb;
OleDbConnection cn;
string connstr="provider=Microsoft.Jet.OLEDB.4.0;Data Source"+数据库文件路径;
cn=new OleDbConncetion(connstr);
cn.Open();
cn.Close();
-----------
C#与(SQL连接)
using System.Data;
using System.Data.SqlClient;
SqlConnection cn;
string connstr="Server=localhost;database=数据库名;uid=sa;pwd=;";
cn=new SqlConncetion(connstr);
cn.Open();
cn.Close();
=========================================================================
楼主
最近看到有不少朋友在问关于数据库连接代码的问题,找了这篇东西给大家看看,希望有帮助
MS Access数据库连接
用DSN连接并且没有用户名和密码:
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "YourDSNName"
%>
用DSN连接并且有用户名和密码:
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "YourDSNName","username","password"
%>
用实际的数据库绝对路径连接:
<%
Set conn = Server.CreateObject("ADODB.Connection")
Strconn="DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ=e:\yanhang\database.mdb"
conn.Open Strconn
%>
用实际的数据库相对路径连接:
<%
Set conn = Server.CreateObject("ADODB.Connection")
Strconn="DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ=" & Server.MapPath("/database/yanhang.mdb")
conn.Open Strconn
%>
MS SQL Server数据库连接
用DSN连接:
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "DSN=MyDSN;UID=user;PWD=password;DATABASE=databasename"
%>
不用DSN连接:
<%
Set conn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={SQL Server};SERVER=ServerName;UID=USER;PWD=password;DATABASE=databasename"
conn.open DSNtemp
%>
FoxPro数据库连接
<%
Set Conn = Server.CreateObject("ADODB.connection")
ConnStr= "Driver=Microsoft Visual Foxpro Driver; UID=userID;SourceType=DBC;SourceDB=C:\yanhang\database.dbc"
Conn.Open ConnStr
%>
Oracle数据库连接:
<%
set conn=server.createobject("adodb.connection")
conn.cursorlocation=adUseClient
DSNTemp="Provider=MSDAORA.1;Password=xxxxx;User ID=yanhang;Data Source=xxx.world"
conn.open DSNtemp
%>
dim cn,rs,sql
set cn=server.createObject("ADODB.Connection")
cn.open "driver={sql server};server=WTW;database=asptest;"&"UID=sa;PWD=admin"
set rs=server.createObject("ADODB.recordset")
rs.open "select * from stu",cn
%>
--------------------------------------
<% '与Access的数库连接并打开数库
Set conn = Server.CreateObject("ADODB.Connection")
connstr="driver={Microsoft Access Driver (*.mdb)};pwd=gws;dbq=" & Server.MapPath("gws.mdb")
conn.open connstr
%>
----------------------------------
C#与(Access ,Excel连接)
using System.Data;
using System.Data.OleDb;
OleDbConnection cn;
string connstr="provider=Microsoft.Jet.OLEDB.4.0;Data Source"+数据库文件路径;
cn=new OleDbConncetion(connstr);
cn.Open();
cn.Close();
-----------
C#与(SQL连接)
using System.Data;
using System.Data.SqlClient;
SqlConnection cn;
string connstr="Server=localhost;database=数据库名;uid=sa;pwd=;";
cn=new SqlConncetion(connstr);
cn.Open();
cn.Close();
=========================================================================
楼主
最近看到有不少朋友在问关于数据库连接代码的问题,找了这篇东西给大家看看,希望有帮助
MS Access数据库连接
用DSN连接并且没有用户名和密码:
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "YourDSNName"
%>
用DSN连接并且有用户名和密码:
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "YourDSNName","username","password"
%>
用实际的数据库绝对路径连接:
<%
Set conn = Server.CreateObject("ADODB.Connection")
Strconn="DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ=e:\yanhang\database.mdb"
conn.Open Strconn
%>
用实际的数据库相对路径连接:
<%
Set conn = Server.CreateObject("ADODB.Connection")
Strconn="DRIVER={Microsoft Access Driver (*.mdb)}; "
Strconn=Strconn & "DBQ=" & Server.MapPath("/database/yanhang.mdb")
conn.Open Strconn
%>
MS SQL Server数据库连接
用DSN连接:
<%
set conn = Server.CreateObject("ADODB.Connection")
conn.open "DSN=MyDSN;UID=user;PWD=password;DATABASE=databasename"
%>
不用DSN连接:
<%
Set conn = Server.CreateObject("ADODB.Connection")
DSNtemp="DRIVER={SQL Server};SERVER=ServerName;UID=USER;PWD=password;DATABASE=databasename"
conn.open DSNtemp
%>
FoxPro数据库连接
<%
Set Conn = Server.CreateObject("ADODB.connection")
ConnStr= "Driver=Microsoft Visual Foxpro Driver; UID=userID;SourceType=DBC;SourceDB=C:\yanhang\database.dbc"
Conn.Open ConnStr
%>
Oracle数据库连接:
<%
set conn=server.createobject("adodb.connection")
conn.cursorlocation=adUseClient
DSNTemp="Provider=MSDAORA.1;Password=xxxxx;User ID=yanhang;Data Source=xxx.world"
conn.open DSNtemp
%>