The error message is as follows:
The following method is written to return the number of rows affected by the data operation:
Copy Code code as follows:
private int Getreturnvalue (string sStr, String conn) {
OleDbConnection odbconn = ACCESSHELP (conn);
OleDbCommand odbcmd = new OleDbCommand (SSTR, odbconn);
Return Odbcmd. ExecuteNonQuery ();
}
Use one of the following methods to invoke this class:
Copy Code code as follows:
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");
}
To send data in this event:
Copy Code code as follows:
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 (' Insert success! ') </script> ");
}
}
After the implementation of the results of the following figure, what is the reason???
I use all the way I can connect to an Access database, and the result is the same, the connection is as follows:
Copy Code code as follows:
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") +;D efaultdir=;D river={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;
}
All the links in my last movie were tested locally, there is no problem, the performance of the same is absolutely no problem, he was in my development this time in the local is good, one to the domain name space to go there is a problem, here I looked at my abnormal problem: abnormal results as shown
The result of the translation of English to say is: The request timeout, the connection pool has reached the highest limit. After watching the heart more cool a section, think back, the original my connection has been the system to their default 15 seconds request time, and then I directly changed the connection time to 1 minutes. such as code:
Copy Code code as follows:
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") +;D efaultdir=;D river={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;
}
As a result, I changed the code to this, which solves the problem of connection timeout.
In the above several writes to the connection database, the instability is the connection pool's default time to change longer, after the change, if in a very card time, non-stop refresh, but, came out there is a serious problem is that the ordinary data loss problem came, the result I use test software to test, did not see the results, Because our local sister has a way to test it out. My configuration and server configuration is a little different, in the said, usually to a server is not the same as our local, as we have a site in use, my class is to connect the SqlHelper connection data SQL database connection mode to the Access database, Class eliminates the problem, I just drop it off with his class, given some parameters, so these are all no problem, can be in a very card time will appear, to look for it, is not to see the results, I later in the English blog to see, originally I do not slightly a property, This property is: Oldbconnection member of the ConnectionTimeout this connection error concurrency time in the end, if you are in a very card case, exactly is the default 30 seconds to see the timeout state, you repair the inside of how the file will return to normal. As a result, I gave this property for 1 minutes and it was normal. I suggest that you do not give too long time, to give a long time, one but really wrong, that is to put someone else's computer card set the screen Oh. Always try this connection on that. After that, less and fewer people will come to visit.
Copy Code code as follows:
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'll 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 is rollbacked or commited, please provide an open Transa Ction. "," 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
}
The above is the class I used, the time position modified. It has been marked with a background.
Oh, this connection is not stable problem to this end.
This article professional technology is ASP.net development, in the time thank you for my blog's attention.
Have a problem also can add me Q I Oh.