四虎精品视频-四虎精品成人免费网站-四虎黄色网-四虎国产视频-国产免费91-国产蜜臀97一区二区三区

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;
}

我的上片中把鏈接的方式全部在本地測(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ù)庫,出現(xiàn)不穩(wěn)定是連接池的默認(rèn)時(shí)間改長些,改了之后,要是在很卡的時(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ù)庫的連接方式改成了連接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ā),在次謝謝你對(duì)我的博客的關(guān)注。
有問題也可以加我Q我哦。

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

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

主站蜘蛛池模板: 石川佑希| 好看女生头像| 抖音下载| 艳妇乳肉豪妇荡乳xxx| 暴走财神1| 游泳池play高h| 破冰 电影| 让我们一起摇太阳| 抖音手机网页版| 黑洞表面豆瓣| 白上之黑| 情难自禁电影| 验光单子的数据怎么看| 欧美黑人乱码avxxxx| 绫濑天| 祝福语生日| 汤唯和梁朝伟拍戏原版| qq经典声音| 吴承恩缉妖录| 好一个中国大舞台简谱| 日韩电影免费在线观看| 九九九九九九伊人| 口舌 — 视频 | vk| 蹲着吐一地呕吐视频| 欧美一级在线视频| 三年电影免费完整| 康熙王朝演员表| 热爱 电影| 欠条怎么写才具有法律效力| 彭丹三级裸奶视频| 我们的高清免费视频观看| 操女孩子| 贾宏| 侦探们的镇魂歌国语版在线观看| 镀金时代第三季什么时候播放| 形容颜色的成语有哪些| 八月照相馆| 美女mm| 本田飞度1.5自动挡多少钱| 凶间雪山| 职业目标评估|