天天躁日日躁狠狠躁AV麻豆-天天躁人人躁人人躁狂躁-天天澡夜夜澡人人澡-天天影视香色欲综合网-国产成人女人在线视频观看-国产成人女人视频在线观看

asp.net Accee數(shù)據(jù)庫連接不穩(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ù)庫所有的方式全用了下,結(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;
}

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

 結(jié)果把英文給翻譯過來說的是:請求超時(shí),連接池已經(jīng)達(dá)到了最高上限制。看完后心多涼了一節(jié),回想了下,原來我的連接已經(jīng)被系統(tǒng)給自己默認(rèn)了15秒請求時(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ù)庫,出現(xiàn)不穩(wěn)定是連接池的默認(rèn)時(shí)間改長些,改了之后,要是在很卡的時(shí)間內(nèi),不停的刷新,可是,就出來了有一個(gè)嚴(yán)重的問題是,平凡的數(shù)據(jù)丟失問題來了,結(jié)果我用測試軟件來測試,沒看到結(jié)果,因?yàn)槲覀儽镜孛糜修k法測試出來,我的配置和服務(wù)器的配置是有點(diǎn)不同的,在說了,通常以個(gè)服務(wù)器不是和我們的本地那樣,就我們一個(gè)網(wǎng)站在用,我的類是把SQLHelper連接數(shù)據(jù)Sql數(shù)據(jù)庫的連接方式改成了連接Access數(shù)據(jù)庫的,類就排除了問題,我只是直接掉用他的類,給了些參數(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分鐘,就正常了。我建議你們別給得太長的時(shí)間了,給長時(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ā),在次謝謝你對我的博客的關(guān)注。
有問題也可以加我Q我哦。

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

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

主站蜘蛛池模板: 男女作爱在线播放免费网页版观看 | 亚洲精品天堂自在久久77 | 欧美性情video sexo视频 | 久啪久久全部视频在线 | 国产精品JK白丝AV网站 | 国产欧美亚洲综合第一页 | xxx69欧美| 国产综合18久久久久久软件 | 亚洲一区二区免费看 | 精品国产成a人在线观看 | 一本大道熟女人妻中文字幕在线 | 日本理伦片午夜理伦片 | 91区国产福利在线观看午夜 | 亚洲一区二区三区91 | 国产欧美一区二区三区在线看 | 野花香在线观看免费高清播放视频 | 翘臀后进美女白嫩屁股视频 | 爽爽影院免费观看 | 床伴在线观看免费高清完整泰剧第四集 | 精品亚洲欧美中文字幕在线看 | 国产福利不卡在线视频 | 国产在线精品亚洲二品区 | 国产不卡无码高清视频 | 亚洲国产精品线在线观看 | 免费人成视频19674不收费 | 国模孕妇模特季玥之粉红 | 姑娘视频日本在线播放 | 国产精品综合AV一区二区国产馆 | 亚洲AV无码乱码A片无码蜜桃 | 一级毛片免费在线播放 | 野花社区视频WWW高清 | 果冻传媒在线观看进入窗口 | 午夜男人免费福利视频 | 红尘影院手机在线观看 | wwwav在线 | 国产AV高清怡春院 | 久久人人玩人妻潮喷内射人人 | 亚洲最大在线视频 | 日本高清免费看 | 国产欧美在线亚洲一区刘亦菲 | 欧美性视频xxxxhd |