最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

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

 更新時間:2009年07月16日 01:19:52   作者:  
我最最進做了個網站,我是用VS2005 + Access 數(shù)據(jù)庫連接,可以我在連接的時候總是出現(xiàn)連接不穩(wěn)定的情況,同樣的代碼,一個字也沒改,就是連接不上,但是有的又連接的上。真是郁悶,真是弄死人。
錯誤信息如下:
寫了如下的一個方法來返回數(shù)據(jù)操作影響的行數(shù):如下
復制代碼 代碼如下:

private int GetReturnValue(string sStr, string conn) {
OleDbConnection odbconn = AccessHelp(conn);
OleDbCommand odbcmd = new OleDbCommand(sStr, odbconn);
return odbcmd.ExecuteNonQuery();
}

用下面的一個方法來調用這個類:
復制代碼 代碼如下:

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

在這個事件中發(fā)送數(shù)據(jù):
復制代碼 代碼如下:

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í)行了之后的結果如下圖,這是什么原因???

我把能連接到Access數(shù)據(jù)庫所有的方式全用了下,結果還是這個樣,連接方式如下:
復制代碼 代碼如下:

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

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

 結果把英文給翻譯過來說的是:請求超時,連接池已經達到了最高上限制??赐旰笮亩鄾隽艘还?jié),回想了下,原來我的連接已經被系統(tǒng)給自己默認了15秒請求時間,后來我直接把連接時間改成了1分鐘。如代碼:

復制代碼 代碼如下:

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

結果我把這些代碼改成了這樣了,就解決了連接超時的問題了。
在上面的幾篇中寫到連接數(shù)據(jù)庫,出現(xiàn)不穩(wěn)定是連接池的默認時間改長些,改了之后,要是在很卡的時間內,不停的刷新,可是,就出來了有一個嚴重的問題是,平凡的數(shù)據(jù)丟失問題來了,結果我用測試軟件來測試,沒看到結果,因為我們本地妹有辦法測試出來,我的配置和服務器的配置是有點不同的,在說了,通常以個服務器不是和我們的本地那樣,就我們一個網站在用,我的類是把SQLHelper連接數(shù)據(jù)Sql數(shù)據(jù)庫的連接方式改成了連接Access數(shù)據(jù)庫的,類就排除了問題,我只是直接掉用他的類,給了些參數(shù)而以,所以這些全是沒什么問題的,可以是在很卡的時間內就會出現(xiàn),去望是找便了,就是沒看到結果,我就在后來在英文的博客中看到,原來我勿略了一個屬性,這個屬性是:OldbConnection成員下的ConnectionTimeout這個連接錯誤并發(fā)時間在什么時間內結束,如果你是在很卡的情況下,正好就是被默認的30秒個定義成看超時狀態(tài),你修下里面的如何文件就會恢復正常。結果我個這個屬性給了個1分鐘,就正常了。我建議你們別給得太長的時間了,給長時間了,一但真的出錯了,那可是要把別人的電腦卡定屏幕的哦??偸窃谀菄L試這連接。那經后就會越來越少的人來訪問了。
復制代碼 代碼如下:

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

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

相關文章

最新評論

阜城县| 都安| 百色市| 万载县| 泊头市| 南投市| 涪陵区| 辽宁省| 来宾市| 迭部县| 婺源县| 来凤县| 乌什县| 睢宁县| 浦东新区| 山阳县| 墨竹工卡县| 万盛区| 怀柔区| 雅安市| 临桂县| 渑池县| 图们市| 扎赉特旗| 阳春市| 沙田区| 七台河市| 襄樊市| 云和县| 岑巩县| 集安市| 武功县| 察雅县| 辽中县| 津南区| 甘孜县| 固镇县| 恩平市| 修水县| 永德县| 乐都县|