用ASP做一个聊天室可是我怎么也连接不了数据库

用ASP做一个聊天室可是我怎么也连接不了数据库,第1张

<%

'dim myconn

'Set myconn=Server.CreateObject("ADODB.Connection")

'myconn.open "FILEDSN=d:\Program Files\Common Files\ODBC\Data 'Sources\wlpData.dsnUID=saPWD=wlpDatabase=Asptest"

Dim myconn

Set myconn=Server.CreateObject("ADODB.Connection")

'myconn.open "driver={Microsoft access Driver (*.mdb)}dbq=" &server.mappath("/data/user.mdb")

connstr="provider=microsoft.jet.oledb.4.0data source=" &server.mappath("/data/data.mdb")

myconn.open connstr

%>

我试过,与连接方式有关系,你看我用标有’的语句就无法连接。而改成这样就可以。你试试吧

<%

Dim myconn

Set myconn=Server.CreateObject("ADODB.Connection")

connstr="provider=microsoft.jet.oledb.4.0data source=" &server.mappath("数据库的相对路径")

myconn.open connstr

%>

using System

using System.Collections

using System.Configuration

using System.Data

using System.Web

using System.Web.Security

using System.Web.UI

using System.Web.UI.HtmlControls

using System.Web.UI.WebControls

using System.Web.UI.WebControls.WebParts

using System.Data.OleDb

using System.IO

/// <summary>

/// Product 的摘要说明

/// </summary>

public class Product : Page

{

public Product()

{

//

// TODO: 在此处添加构造函数逻辑

//

}

public void Add_product(string name, DateTime date, int visit, string path, string intro, string link)

{

try

{

OleDbConnection thisConnection = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0DATA Source=" + System.Web.HttpContext.Current.Server.MapPath("~/App_Data\\comdata.aspx"))//你的数据库

thisConnection.Open()

string str = "insert into Production (p_name,p_date,p_visit,p_path,p_intro,p_link) values('" + name + "','" + date + "','" + visit + "','" + path + "','" + intro + "','" + link + "')"

OleDbCommand npcd = new OleDbCommand(str, thisConnection)

npcd.ExecuteNonQuery()

thisConnection.Close()

((Page)HttpContext.Current.CurrentHandler).ClientScript.RegisterStartupScript(this.GetType(), "", "alert('添加服务信息成功!')", true)

}

catch (Exception e)

{

Response.Write(e.ToString())

//Server.Transfer("error.aspx")

}

}

public void Del_product(string name)

{

try

{

string path

OleDbConnection thisConnection = new OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0DATA Source=" + System.Web.HttpContext.Current.Server.MapPath("~/App_Data\\comdata.aspx"))//你的数据库

OleDbDataAdapter thisAdapter = new OleDbDataAdapter("select * from Production where p_name=" + "'" + name + "'", thisConnection)

OleDbCommandBuilder thisBuilder = new OleDbCommandBuilder(thisAdapter)

DataSet thisDataSet = new DataSet()

thisAdapter.Fill(thisDataSet, "Table_pro")

if (thisDataSet.Tables["Table_pro"].Rows.Count == 1)

{

path = System.Web.HttpContext.Current.Server.MapPath(@"~/Product_image\" + thisDataSet.Tables["Table_pro"].Rows[0]["p_path"].ToString())

FileInfo fi = new FileInfo(path)

fi.Delete()

FileInfo fi2 = new FileInfo(System.Web.HttpContext.Current.Server.MapPath(@"~/Product_intro\" + thisDataSet.Tables["Table_pro"].Rows[0]["p_link"].ToString()))

fi2.Delete()

thisDataSet.Tables["Table_pro"].Rows[0].Delete()

thisAdapter.Update(thisDataSet, "Table_pro")

}

thisConnection.Close()

((Page)HttpContext.Current.CurrentHandler).ClientScript.RegisterStartupScript(this.GetType(), "", "alert('删除服务信息成功!')", true)

}

catch

{

Server.Transfer("Error.html")

}

}

}

以前写的对数据可 *** 作的代码,你稍微改写就可以用了,希望对你有用

连不上数据库只能上是边的代码问题,没必要都贴出来

require_once("sys_conf.inc")

$link_id=mysql_connect($DBHOST,$DBUSER,$DBPWD) or die("无法连接数据库!1")

在两句中间打印一下$DBHOST,$DBUSER,$DBPWD,,然后用这个登陆一下phpmyadmin看能登陆上不行就说明帐号密码或服务器设置错了


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/sjk/9616267.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-04-30
下一篇 2023-04-30

发表评论

登录后才能评论

评论列表(0条)

保存