當前位置:首頁 » 操作系統 » asp鏈接資料庫

asp鏈接資料庫

發布時間: 2022-08-23 06:16:05

1. 如何用asp連接資料庫

我給你個連接串吧。
把你這裡面的全部換成我的就行。

Dim Conn,ConnStr
ConnStr="Driver={sql Server};Server=(local);Uid=sa;Pwd=123;Database=Bjx_Data;"
On Error Resume Next
Set Conn = Server.CreateObject("ADODB.Connection")
Conn.Open ConnStr
Uid 登錄名

Pwd 密碼

Database 資料庫名

2. asp連接SQL server資料庫二種方法

asp教程連接sql
server資料庫教程二種方法
本教程主要是講了asp與mssql
server
資料庫的兩種不同的連接方法,主要是講sql
server連接方法與sql
server
ole
db連接方法。
sql
server連接方法:
set
adocon=server.createobject("adodb.recordset")
adocon.open"driver={sql
server};server=(local);uid=***;pwd=***;"&
_
"database=資料庫名;"
sql
server
ole
db連接方法:
set
adocon=server.createobject("adodb.connection")
adocon.open"provider=sqloledb.1;data
source=ritant4;"&
_
"user
id=***;password=***;"&
_
"inital
catalog=資料庫名"

3. ASP怎麼連接SQL資料庫

usingSystem;
usingSystem.Collections.Generic;
usingSystem.Linq;
usingSystem.Web;
usingSystem.Web.UI;
usingSystem.Web.UI.WebControls;
usingSystem.Data.SqlClient;//注意需要添加此句

namespaceaspnet3
{
publicpartialclassdatatest:System.Web.UI.Page
{
protectedvoidPage_Load(objectsender,EventArgse)
{
stringstrconn="server=localhost;uid=sa;pwd=longlt;database=School";
SqlConnectionconn=newSqlConnection(strconn);//創建連接
stringsql="select*fromstudents";
conn.Open();
SqlCommandcmd=newSqlCommand(sql,conn);//執行查詢
Response.Write("連接成功");
SqlDataReaderdr=cmd.ExecuteReader();//查詢結果
if(dr.Read())
{
//利用dr[索引]對資料庫表進行操作,dr[]返回object;
//可以用欄位做索引,也可用列號0,1..做索引
Response.Write(dr[0].ToString()+"<br>");
}

//this.Lab.Text="suc";
}
}
}

在上面的例子中,我們連接了一個sa下的School資料庫,並查詢了其中students欄位的內容。

連接資料庫分為三個步驟:先定義連接信息,再創建一個連接,最後打開連接

stringstrconn="server=localhost;uid=sa;pwd=longlt;database=School";//在這一段修改資料庫的信息
SqlConnectionconn=newSqlConnection(strconn);//創建連接
conn.Open();//打開連接

4. asp網頁如何訪問資料庫

在asp動態語言頁面中連接資料庫是通過asp內部的ADO組件通過ODBC完成。
1、首先應創建 Connection 對象的實例。
下面的腳本創建 Connection 對象
<%
'Create a connection object
Set cn = Server.CreateObject("ADODB.Connection")
'Open a connection; the string refers to the DSN
%>

2、接著打開資料庫連接:
cn.Open "FILEDSN=MyDatabase.dsn"
注意:無論在等號 (=) 之前還是之後,DSN 字元串都不能包含空格。
在這種情況下,Connection 對象的 Open 方法引用基於 DSN 的文件,其中包含關於資料庫的位置和配置信息。也可以不引用 DSN,直接顯式引用供應程序、數據源、用戶 ID 和密碼。
3、連接過程:
<%

Set cn = Server.CreateObject("ADODB.Connection") '創建資料庫連接對象
Set rsCustomers = Server.CreateObject("ADODB.Recordset") '創建資料庫查詢對象
cn.Open "FILEDSN=SQLlink.dsn" '打開資料庫
strSQL = "SELECT username,password FROM [myDatabase].[dbo].[user] where username='guying'"
rsCustomers.Open strSQL, cn '運行SQL語句
%>
4、處理資料庫返回數據
Set username1= rsCustomers("username") '獲取username欄位的返回結果
Set password1= rsCustomers("password") '獲取password欄位的返回結果
Do Until rsCustomers.EOF
Response.Write username1 & " " & password1 & "<BR>"
rsCustomers.MoveNext
Loop '通過循環獲取所有返回記錄

5. asp怎麼連接access資料庫

set conn=server.createobject("adodb.connection")建立資料庫連接對象
dbpath=server.mappath("datebase/stmanager.mdb")將資料庫相對路勁賦給變數dbpath
conn.open "driver={microsoft access driver (*.mdb)};dbq="& dbpath
打開數據連接

連接所有的資料庫都要先建立數據的連接對象和記錄集對象,要就是connection和recordset ,conn.open後面的語句是資料庫引擎,有幾種寫法,你這是一種,還有就是sql資料庫和access的連接代碼是不是一樣的

建立記錄集對象
set rs=server.createobject("adodb.recordset")

給你一段讀取資料庫的代碼,你自己仔細看看就好了

set conn=server.createobject("adodb.connection")
dbpath=server.mappath("datebase/stmanager.mdb")
conn.open "driver={microsoft access driver (*.mdb)};dbq="& dbpath
set rs=server.createobject("adodb.recordset")
sql="select * from xxx"
rs.open sql,conn,1,1
引用的時候用格式
rs("xxx")
就可用了
其中sql後面引號裡面的xxx表示stmanager資料庫裡面名叫xxx的表
後面的xxx表示一個欄位名

6. ASP 怎麼連接SQL資料庫

ASP與SQL資料庫連接語句具體如下:

Set conn = Server.CreateObject("ADODB.Connection")
connstr = "provider=Sqloledb;server=伺服器名;uid=用戶名;pwd=密碼;database=資料庫名"
conn.Open connstr
If Err Then
err.Clear
Set conn = Nothing
Response.Write "資料庫連接出錯,請檢查連接字串"
Response.End

(6)asp鏈接資料庫擴展閱讀:

SQL常用命令使用方法:

(1) 數據記錄篩選:

sql="select * from 數據表 where 欄位名=欄位值 order by 欄位名 "

sql="select * from 數據表 where 欄位名 like 『%欄位值%『 order by 欄位名 "

sql="select top 10 * from 數據表 where 欄位名 order by 欄位名 "

sql="select * from 數據表 where 欄位名 in (『值1『,『值2『,『值3『)"

sql="select * from 數據表 where 欄位名 between 值1 and 值2"

(2) 更新數據記錄:

sql="update 數據表 set 欄位名=欄位值 where 條件表達式"

sql="update 數據表 set 欄位1=值1,欄位2=值2 …… 欄位n=值n where 條件表達式"

(3) 刪除數據記錄:

sql="delete from 數據表 where 條件表達式"

sql="delete from 數據表" (將數據表所有記錄刪除)

7. asp網頁怎樣連接SQL資料庫

asp連接資料庫的代碼為:
Set conn = Server.CreateObject(ADODB.Connection);
conn.Opendriver={SQLServer};server=202.108.32.94;uid=wu77445;pwd=p780522;database=w
ww_panwei_com;conn open其中/Set conn = Server.CreateObject(ADODB.Connection)為設置一個資料庫的連接對象
driver=()告訴連接的設備名是SQL-SERVER
server是連接的伺服器的ip地址,Uid是指用戶的用戶名,pwd是指的用戶的password,
database是用戶資料庫在伺服器端的資料庫的名稱

8. 請問高手,ASP連接資料庫程序怎樣寫

ASP與Access資料庫連接:
<%
dim
conn,mdbfile
mdbfile=server.mappath("資料庫名稱.mdb")
set
conn=server.createobject("adodb.connection")
conn.open
"driver={microsoft
access
driver
(*.mdb)};uid=admin;pwd=資料庫密碼;dbq="&mdbfile
%>
ASP與SQL資料庫連接:
<%
dim
conn
set
conn=server.createobject("ADODB.connection")
con.open
"PROVIDER=SQLOLEDB;DATA
SOURCE=SQL伺服器名稱或IP地址;UID=sa;PWD=資料庫密碼;DATABASE=資料庫名稱
%>

9. ASp連接資料庫

用的最多的就是ACCESS和SQL Server資料庫,連接語句如下:

1. ASP連接Access資料庫語句

Set Conn=Server.CreateObject("ADODB.Connection")
Connstr="DBQ="+server.mappath("www/bbs.mdb")+";DefaultDir=;DRIVER={Microsoft
AccessDriver(*.mdb)};"
Conn.Open connstr

其中Set Conn=Server.CreateObject("ADODB.Connection")為建立一個訪問數據的對象
server.mappath("www/bbs.mdb")是告訴伺服器access 資料庫訪問的路徑

2. ASP連接Sqlserver資料庫語句

Set conn = Server.CreateObject("ADODB.Connection")
conn.Open"driver={SQLServer};server=202.108.32.94;uid=wu77445;pwd=p780522;database=w
ww_panwei_com"
conn open
其中/Set conn = Server.CreateObject("ADODB.Connection")為設置一個資料庫的連接對象
driver=()告訴連接的設備名是SQL-SERVER
server是連接的伺服器的ip地址,Uid是指用戶的用戶名,pwd是指的用戶的password,
database是用戶資料庫在伺服器端的資料庫的名稱

10. 在asp中怎麼連接Access資料庫

asp連接access資料庫的方法:
1、設置資料庫連接方式:
set dbconnection=Server.CreateObject("ADODB.Connection")
DBPath = Server.MapPath("customer.mdb")
dbconnection.Open "provider=microsoft.jet.oledb.4.0;data source="&dbpath
SQL="select * from auth where id='" & user_id &"'"
SET uplist=dbconnection.EXECUTE(SQL)
2、設置連接資料庫
DBPath = Server.MapPath("customer.mdb")
set session("rs")=Server.CreateObject("ADODB.Recordset")
' rs=Server.CreateObject("ADODB.Recordset")
connstr="provider=microsoft.jet.oledb.4.0;data source="&dbpath
SQL="select * from auth where id='" & user_id &"'"
session("rs").Open sql,connstr,1,3
3、建立odbc數據源
set conn=server.createobject("Adodb.connection")
conn.open "DSN=xxx;UID=;PWD=;Database=customer
4、附上一個經常用的sqlserver與access通用的連接資料庫代碼:
<%
Const DataBaseType=1
If DataBaseType=0 then
DBPath="/jb51/news.asp"
SqlNowString = "Now()"
ystr=true
nstr=false
suiji="rnd(id)"
Else
'如果是SQL資料庫,請認真修改好以下資料庫選項
DataServer = "wwwjb51net" '資料庫伺服器IP
DataUser = "jb51net" '訪問資料庫用戶名
DataBaseName = "jb51net" '資料庫名稱
DataBasePsw = "密碼" '訪問資料庫密碼
SqlNowString = "getdate()"
ystr=1
nstr=0
suiji="newid()"
End if
On Error Resume Next
If DataBaseType = 1 Then
ConnStr="driver={SQL Server};server="&dataserver&";UID="&datauser&";PWD="&databasepsw&";Database="&databasename
Else
ConnStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath(DBPath)
End If
Set conn = Server.CreateObject("ADODB.Connection")
conn.open ConnStr
If Err Then Err.Clear:Set conn = Nothing:Response.Write "資料庫連接出錯,請檢查Conn.asp文件中的資料庫參數設置。":Response.End
%>

熱點內容
超級訪問陳小春應采兒 發布:2025-05-16 09:43:29 瀏覽:478
緩存視頻合並工具最新版 發布:2025-05-16 09:35:03 瀏覽:194
花雨庭伺服器ip地址和埠 發布:2025-05-16 09:34:58 瀏覽:239
同時修改多台伺服器管理地址工具 發布:2025-05-16 09:20:36 瀏覽:421
什麼配置就能玩地平線 發布:2025-05-16 09:13:46 瀏覽:82
python旋轉圖片 發布:2025-05-16 09:13:40 瀏覽:638
少女前線防檢測腳本 發布:2025-05-16 08:59:07 瀏覽:728
編譯器對系統的依賴 發布:2025-05-16 08:37:29 瀏覽:711
javamap數組 發布:2025-05-16 08:37:28 瀏覽:451
移動光貓如何自行修改密碼 發布:2025-05-16 08:20:15 瀏覽:125