一区二区久久-一区二区三区www-一区二区三区久久-一区二区三区久久精品-麻豆国产一区二区在线观看-麻豆国产视频

asp.net Accee數(shù)據(jù)庫(kù)連接不穩(wěn)定解決方案

錯(cuò)誤信息如下:
寫了如下的一個(gè)方法來返回?cái)?shù)據(jù)操作影響的行數(shù):如下
復(fù)制代碼 代碼如下:
private int GetReturnValue(string sStr, string conn) {
OleDbConnection odbconn = AccessHelp(conn);
OleDbCommand odbcmd = new OleDbCommand(sStr, odbconn);
return odbcmd.ExecuteNonQuery();
}

用下面的一個(gè)方法來調(diào)用這個(gè)類:
復(fù)制代碼 代碼如下:
public int wsbm(string[] str) {
StringBuilder sb=new StringBuilder();
sb.Append("INSERT INTO ").Append("wsbm(zy, studentname, parentname)");
sb.Append(" VALUES (");
sb.Append("'" + str[0] + "', '" + str[1] + "', '" + str[2] + "'");
sb.Append(")");
return GetReturnValue(sb.ToString(), "ODBconn");
}

在這個(gè)事件中發(fā)送數(shù)據(jù):
復(fù)制代碼 代碼如下:
protected void Bttj_Click(object sender, EventArgs e) {
string[] sStr = new string[] {
this.ddlzy.SelectedItem.Text,
this.tbName.Text,
this.tbbb.Text,
};
if (ad.wsbm(sStr) > 0) {
Response.Write("<script>alert('插入成功!')</script>");
}
}

執(zhí)行了之后的結(jié)果如下圖,這是什么原因???

我把能連接到Access數(shù)據(jù)庫(kù)所有的方式全用了下,結(jié)果還是這個(gè)樣,連接方式如下:
復(fù)制代碼 代碼如下:
private OleDbConnection AccessHelp(string str){
OleDbConnection odbconn = new OleDbConnection();
try{
string sStr2 = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source=" + Server.MapPath(@"App_Data/#fdaeg35@#gds.mdb");
odbconn.ConnectionString = sStr2;
if (odbconn.State == ConnectionState.Closed){
odbconn.Open();
}
else{
sStr2 = "DBQ=" + Server.MapPath(@"App_Data/#fdaeg35@#gds.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};";
odbconn.ConnectionString = sStr2;
if (odbconn.State == ConnectionState.Closed){
odbconn.Open();
}
}
}
catch{
try{
//odbconn = new OleDbConnection(ConfigurationManager.ConnectionStrings[str].ConnectionString);
odbconn.ConnectionString = ConfigurationManager.ConnectionStrings[str].ConnectionString;
if (odbconn.State == ConnectionState.Closed){
odbconn.Open();
}
}
catch{
string sStr1 = @"Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;Data Source=./App_Data/#fdaeg35@#gds.mdb";
//odbconn = new OleDbConnection(sStr1);
odbconn.ConnectionString = sStr1;
if (odbconn.State == ConnectionState.Closed){
odbconn.Open();
}
}
}
return odbconn;
}

我的上片中把鏈接的方式全部在本地測(cè)試了下,一點(diǎn)問題也沒有,性能方面一樣是絕對(duì)沒問題的,他是在我開發(fā)完這個(gè)的時(shí)候在本地是好的,一發(fā)到域名空間去就有問題來了,這里我看了下我的異常問題:異常結(jié)果如圖

 結(jié)果把英文給翻譯過來說的是:請(qǐng)求超時(shí),連接池已經(jīng)達(dá)到了最高上限制。看完后心多涼了一節(jié),回想了下,原來我的連接已經(jīng)被系統(tǒng)給自己默認(rèn)了15秒請(qǐng)求時(shí)間,后來我直接把連接時(shí)間改成了1分鐘。如代碼:
復(fù)制代碼 代碼如下:
private OleDbConnection AccessHelp(string str) {
OleDbConnection odbconn = new OleDbConnection();
try {
string sStr2 = "Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;connection timeout=120;Data Source=" + Server.MapPath(@"App_Data/#fdaeg35@#gds.mdb");
odbconn.ConnectionString = sStr2;
if (odbconn.State == ConnectionState.Closed) {
odbconn.Open();
}
else{
sStr2 = "DBQ=" + Server.MapPath(@"App_Data/#fdaeg35@#gds.mdb") + ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};connection timeout=120;";
odbconn.ConnectionString = sStr2;
if (odbconn.State == ConnectionState.Closed) {
odbconn.Open();
}
}
}
catch {
try {
//odbconn = new OleDbConnection(ConfigurationManager.ConnectionStrings[str].ConnectionString);
odbconn.ConnectionString = ConfigurationManager.ConnectionStrings[str].ConnectionString;
if (odbconn.State == ConnectionState.Closed) {
odbconn.Open();
}
}
catch {
string sStr1 = @"Provider=Microsoft.Jet.OLEDB.4.0;Persist Security Info=false;connection timeout=120;Data Source=./App_Data/#fdaeg35@#gds.mdb";
//odbconn = new OleDbConnection(sStr1);
odbconn.ConnectionString = sStr1;
if (odbconn.State == ConnectionState.Closed) {
odbconn.Open();
}
}
}
return odbconn;
}

結(jié)果我把這些代碼改成了這樣了,就解決了連接超時(shí)的問題了。
在上面的幾篇中寫到連接數(shù)據(jù)庫(kù),出現(xiàn)不穩(wěn)定是連接池的默認(rèn)時(shí)間改長(zhǎng)些,改了之后,要是在很卡的時(shí)間內(nèi),不停的刷新,可是,就出來了有一個(gè)嚴(yán)重的問題是,平凡的數(shù)據(jù)丟失問題來了,結(jié)果我用測(cè)試軟件來測(cè)試,沒看到結(jié)果,因?yàn)槲覀儽镜孛糜修k法測(cè)試出來,我的配置和服務(wù)器的配置是有點(diǎn)不同的,在說了,通常以個(gè)服務(wù)器不是和我們的本地那樣,就我們一個(gè)網(wǎng)站在用,我的類是把SQLHelper連接數(shù)據(jù)Sql數(shù)據(jù)庫(kù)的連接方式改成了連接Access數(shù)據(jù)庫(kù)的,類就排除了問題,我只是直接掉用他的類,給了些參數(shù)而以,所以這些全是沒什么問題的,可以是在很卡的時(shí)間內(nèi)就會(huì)出現(xiàn),去望是找便了,就是沒看到結(jié)果,我就在后來在英文的博客中看到,原來我勿略了一個(gè)屬性,這個(gè)屬性是:OldbConnection成員下的ConnectionTimeout這個(gè)連接錯(cuò)誤并發(fā)時(shí)間在什么時(shí)間內(nèi)結(jié)束,如果你是在很卡的情況下,正好就是被默認(rèn)的30秒個(gè)定義成看超時(shí)狀態(tài),你修下里面的如何文件就會(huì)恢復(fù)正常。結(jié)果我個(gè)這個(gè)屬性給了個(gè)1分鐘,就正常了。我建議你們別給得太長(zhǎng)的時(shí)間了,給長(zhǎng)時(shí)間了,一但真的出錯(cuò)了,那可是要把別人的電腦卡定屏幕的哦。總是在那嘗試這連接。那經(jīng)后就會(huì)越來越少的人來訪問了。
復(fù)制代碼 代碼如下:
private static void PrepareCommand(OldbCommand command, OldbConnection connection, OldbTransaction transaction, CommandType commandType, string commandText, SqlParameter[] commandParameters, out bool mustCloseConnection) {
if (command == null) throw new ArgumentNullException("command");
if (commandText == null || commandText.Length == 0) throw new ArgumentNullException("commandText");
// If the provided connection is not open, we will open it
if (connection.State != ConnectionState.Open) {
mustCloseConnection = true;
connection.Open();
}
else {
mustCloseConnection = false;
}
// Associate the connection with the command
command.Connection = connection;
// Set the command text (stored procedure name or SQL statement)
command.CommandText = commandText;
//Set the command Time
command.CommandTimeout = 60;
// If we were provided a transaction, assign it
if (transaction != null) {
if (transaction.Connection == null) throw new ArgumentException("The transaction was rollbacked or commited, please provide an open transaction.", "transaction");
command.Transaction = transaction;
}
// Set the command type
command.CommandType = commandType;
// Attach the command parameters if they are provided
if (commandParameters != null) {
AttachParameters(command, commandParameters);
}
return;
}

上面是我用的那個(gè)類,修改的時(shí)間位置。已經(jīng)用背景標(biāo)出來了。
呵呵,這個(gè)連接不穩(wěn)定的問題到此就結(jié)束了。
本文專業(yè)技術(shù)是ASP.NET開發(fā),在次謝謝你對(duì)我的博客的關(guān)注。
有問題也可以加我Q我哦。

AspNet技術(shù)asp.net Accee數(shù)據(jù)庫(kù)連接不穩(wěn)定解決方案,轉(zhuǎn)載需保留來源!

鄭重聲明:本文版權(quán)歸原作者所有,轉(zhuǎn)載文章僅為傳播更多信息之目的,如作者信息標(biāo)記有誤,請(qǐng)第一時(shí)間聯(lián)系我們修改或刪除,多謝。

主站蜘蛛池模板: 91成人高清在线播放 | 亚洲美女aⅴ久久久91 | 国产午夜精品久久久久九九 | 欧美人与牲动交xxxxbbbb | 国产剧情在线视频 | 在线看的黄色网址 | 四虎在线视频免费观看 | 一级美女 | 国产全部理论片线观看 | 国产永久视频 | 最新精品亚洲成a人在线观看 | jizz国产视频 | 日韩欧美一中文字幕不卡 | 深爱婷婷网 | 色cccwww | 色婷婷天天综合在线 | 久久天天丁香婷婷中文字幕 | 4hu四虎永久网址 | 欧美日韩国产亚洲人成 | 49pao强力在线高清基地 | 91麻豆精品国产91久久久 | 中文字幕不卡一区 | 日韩亚洲一区二区三区 | 色综合久久综合欧美综合图片 | 伊人免费视频二 | 91在线一区二区 | japanese无码中文字幕 | 色国产精品 | 色视频免费观看高清完整 | 综合网在线观看 | 99热国产在线观看 | 91久久精一区二区三区大全 | 国产精品成人亚洲 | 国产亚洲一区二区在线观看 | 中文字幕在线有码 | 一区二区三区国产 | 国产成人激烈叫床声视频对白 | 久久视热这只是精品222 | 国产综合视频 | 精品国产制服丝袜高跟 | 精品久久久久久久久久久 |