Hello, I am getting this error time to time randomly. My web application is built on asp.net 3.5 which uses ODBC 5.1 driver to connect to mysql database. I have a separate database class which handles the connection, execute, fetching and all. The application runs fine for sometime then suddenly the users start getting this error after which the application fails to insert select from database. I have posted in this forum couple of times now and no one is really contributing or helping me. Please..Any help will be highly appreciated.. Many thanks, Viv
![]() |
0 |
![]() |
The database abstract looks like this.. ***************************************************************************************using System; using System.Collections.Generic; using System.Text; using System.Data; using System.IO; using System.Data.Odbc; using System.Web; using System.Web.Security; using System.Web.UI; using System.Web.UI.HtmlControls; using System.Web.UI.WebControls; using System.Web.UI.WebControls.WebParts; namespace Dbconnect { public static class Database { private static long _numQueries = 0; private static OdbcConnection _connection = null; private static bool _isOpen = false, _gettingInput = false, _dbIsBusy = false; private static string _dsn = ""; private static System.Windows.Forms.DialogResult _userInput = System.Windows.Forms.DialogResult.None; public static long NumQueries { get { return _numQueries; } set { _numQueries = value; } } public static bool isDBBusy() { return _dbIsBusy; } public static void setDSN(string dsn) { if (_isOpen) return; _dsn = dsn; _connection = new OdbcConnection("DSN=" + _dsn); //_connection.ConnectionTimeout = 1; } public static bool useDB() { // if (!_isOpen) // return false; // if (_connection.State != ConnectionState.Open) // { // int timePassed = 0; // while (_connection.State != ConnectionState.Open && timePassed = 3000) // return false; // } // _dbIsBusy = true; return true; } public static void finishDB() { // _dbIsBusy = false; } public static bool Connect() { _isOpen = false; try { _connection.Open(); } catch (Exception ex) { /* StringBuilder builder = new StringBuilder(); string sMsg = ex.Message; builder.Append(""); sMsg = sMsg.Replace("\"", "'"); builder.Append("alert( \"" + sMsg + "\" );"); builder.Append(""); HttpContext.Current.Response.Write(builder.ToString()); */ HttpContext.Current.Response.Write(ex.Message); return false; } //if (_connection.State != System.Data.ConnectionState.Open) // return false; _isOpen = true; return true; } public static void Disconnect() { if (null != _connection) _connection.Close(); _isOpen = false; } public static bool TestConnection() { bool result = Connect(); if (result) Disconnect(); return result; } public static bool DatabaseSynchronizing() { DataTable dt = new DataTable(); int numRows = 0; bool synchronizing = true; if (GetData("select synchronizing from client_branch;", ref numRows, dt)) { if (numRows > 0) { if (!GetBoolean(ref synchronizing, dt, 0, "synchronizing")) { synchronizing = true; } } } if (dt != null) dt.Dispose(); return synchronizing; } public static void WaitUntilReady() { //bool available = false; //while (!available) //{ // available = !DatabaseSynchronizing(); // if (!available) // System.Threading.Thread.Sleep(50); //} } public static bool dbErrorContinue() { if (_gettingInput) return false; _gettingInput = true; _userInput = System.Windows.Forms.DialogResult.None; Disconnect(); do { // _userInput = SmartMessageBox.ShowRetryCancel("Network connection to the local branch server is down."); } while (_userInput == System.Windows.Forms.DialogResult.Retry && !Connect()); _gettingInput = false; return (_userInput == System.Windows.Forms.DialogResult.Retry); } public static string escapeSlashes(string command) { string result = ""; for (int i = 0; i 65535) { //SmartMessageBox.ShowMessage( // "Error: This update is too large to be synchronized. " + // "Please contact Vandoes Computer Systems and quote the following information:\n" + // "'Update too large' - '" + command.Substring(0, 20) + "'"); } else { SendSyncCommand(command); } } _numQueries++; return true; } public static bool RunCalculation(string command, ref object output) { //if (!useDB()) // return false; bool success = false;//, abort = false; //while (!success && !abort) //{ try { if (_isOpen == false) { Connect(); } OdbcCommand c = _connection.CreateCommand(); c.CommandText = command; c.CommandTimeout = 3; c.CommandType = CommandType.Text; output = c.ExecuteScalar(); success = true; } catch (Exception e) { // SmartMessageBox.ShowMessage(e.GetType().ToString() + ": " + e.Message); // if (!dbErrorContinue()) // abort = true; } finally { Disconnect(); } //} //finishDB(); if (!success) return false; if (output is DBNull) return false; _numQueries++; return true; } public static bool GetData(string query, ref int numRows, DataTable dt) { //if (!useDB()) // return false; bool success = false;//, abort = false; //while (!success && !abort) //{ try { if (_isOpen == false) { Connect(); } OdbcCommand c = _connection.CreateCommand(); c.CommandText = query; //c.CommandTimeout = 3; c.CommandType = CommandType.Text; OdbcDataAdapter da = new OdbcDataAdapter(c); numRows = da.Fill(dt); //da.Dispose(); success = true; } catch { //SmartMessageBox.ShowMessage(e.GetType().ToString() + ": " + e.Message); //if (!dbErrorContinue()) // abort = true; } finally { Disconnect(); } //} //finishDB(); _numQueries++; return success; } public static bool GetChar(ref char output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = '\0'; else { // Write Invalid data type to log file... //if (!(data is string)) if (data.ToString() != "") output = Convert.ToChar(data); } return true; } public static bool GetString(ref string output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = ""; else { // Write Invalid data type to log file... //if (!(data is string)) output = Convert.ToString(data); output.Replace("\\", ""); } return true; } public static bool GetBlob(ref byte[] output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = null; else { // Write Invalid data type to log file... //if (!(data is byte[])) if (data is byte[]) output = (byte[])data; else { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' not of type 'blob'."); return false; } } return true; } /* public static bool GetImage(ref Image output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { //SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; byte[] rawData = null; MemoryStream myStream = null; if (data is DBNull) output = null; else { // Write Invalid data type to log file... //if (!(data is byte[])) if (data is byte[]) { // Get the image from bytes rawData = (byte[])data; if (rawData.Length == 0) { output = null; return true; } try { myStream = new MemoryStream(rawData); output = Bitmap.FromStream(myStream, true, true); } catch (Exception) { output = null; // SmartMessageBox.ShowMessage("Error in database. Data in field '" + field + "' is not a valid image."); return true; } } else { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' not of type 'image'."); return false; } } return true; } */ public static bool GetShort(ref short output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = -1; else { // Write Invalid data type to log file... //if (!(data is Int16)) output = Convert.ToInt16(data); } return true; } public static bool GetInt(ref int output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = -1; else { // Write Invalid data type to log file... //if (!(data is Int32)) output = Convert.ToInt32(data); } return true; } public static bool GetULong(ref ulong output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = 0; else { // Write Invalid data type to log file... //if (!(data is Decimal || data is Int64)) output = Convert.ToUInt64(data); } return true; } public static bool GetLong(ref long output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = -1; else { // Write Invalid data type to log file... //if (!(data is Int64)) output = Convert.ToInt64(data); } return true; } public static bool GetDouble(ref double output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = 0.00; else { // Write Invalid data type to log file... //if (!(data is Double)) output = Convert.ToDouble(data); } return true; } public static bool GetFloat(ref float output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = 0.0f; else { // Write Invalid data type to log file... //if (!(data is Single)) output = Convert.ToSingle(data); } return true; } public static bool GetDecimal(ref decimal output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = 0.00m; else { // Write Invalid data type to log file... //if (!(data is Decimal)) output = Convert.ToDecimal(data); } return true; } public static bool GetBoolean(ref bool output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = false; else { // Write Invalid data type to log file... //if (!(data is Int16)) output = Convert.ToBoolean(data); } return true; } public static bool GetDate(ref DateTime output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = DateTime.MinValue; else { // Write Invalid data type to log file... //if (!(data is DateTime)) if (data is DateTime) output = (DateTime)data; else { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' not of type 'date'."); return false; } } return true; } public static bool GetTime(ref TimeSpan output, DataTable dt, int row, string field) { DataColumn column = dt.Columns[field]; if (column == null) { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist."); return false; } object data = dt.Rows[row][column]; if (data is DBNull) output = TimeSpan.MinValue; else { // Write Invalid data type to log file... //if (!(data is TimeSpan)) if (data is TimeSpan) output = (TimeSpan)data; else { // SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' not of type 'time'."); return false; } } return true; } } }
![]() |
0 |
![]() |
Hi vivekkrish2001,
From the description, we couldn't understand your question clearly. Could you please tell us the exact error? Also, please format the source code so that we can see it easily.
Thanks.
David Qian
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |
Hello Wencui, Thanks for your reply, i almost gave up hope on this asp.net forums. Well i explain it again, i have built an asp.net 3.5 web aaplication whihc uses odbc driver 5.1 to connect to a mysql backend database. The application involves numerous queries and database transactions and is accessed by multiple users at same time. For some time the application works fine without any problem i.e. it performs query insert update etc etc on the database without any problem. After some time say 1 hour of continuos use, the application suddenly crashes. I have placed a HTTP context in my database abstract to write the error on my screen. The error users get is "The connection is already open, the connection state is reconnecting". If i wait for 4-5 mins and ask users to refresh the page then it works without any problem again for next 10-15 mins. I have enabled ODBCconnection pooling as well. Is there any way for me to attach the database class file here? when i copy paste the formatting goes bad and becomes insensible. Email address or anything?. Many thanks, Vivek
![]() |
0 |
![]() |
Hello Wencui,
Thanks for your reply, i almost gave up hope on this asp.net forums. Well i explain it again, i have built an asp.net 3.5 web aaplication whihc uses odbc driver 5.1 to connect to a mysql backend database. The application involves numerous queries and database transactions and is accessed by multiple users at same time. For some time the application works fine without any problem i.e. it performs query insert update etc etc on the database without any problem. After some time say 1 hour of continuos use, the application suddenly crashes. I have placed a HTTP context in my database abstract to write the error on my screen. The error users get is "The connection is already open, the connection state is reconnecting". If i wait for 4-5 mins and ask users to refresh the page then it works without any problem again for next 10-15 mins. I have enabled ODBCconnection pooling as well.Is there any way for me to attach the database class file here? Find the databse class scross down
Many thanks,
Vivek
using System;
using System.Collections.Generic;
using System.Text;
using System.Data;
using System.IO;
using System.Data.Odbc;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
namespace Dbconnect
{
public static class Database
{
private static long _numQueries = 0;
private static OdbcConnection _connection = null;
private static bool _isOpen = false, _gettingInput = false, _dbIsBusy = false;
private static string _dsn = "";
private static System.Windows.Forms.DialogResult _userInput = System.Windows.Forms.DialogResult.None;
public static long NumQueries { get { return _numQueries; } set { _numQueries = value; } }
public static bool isDBBusy() { return _dbIsBusy; }
public static void setDSN(string dsn)
{
if (_isOpen)
return;
_dsn = dsn;
_connection = new OdbcConnection("DSN=" + _dsn);
//_connection.ConnectionTimeout = 1;
}
public static bool useDB()
{
// if (!_isOpen)
// return false;
// if (_connection.State != ConnectionState.Open)
// {
// int timePassed = 0;
// while (_connection.State != ConnectionState.Open && timePassed < 3000)
// {
// System.Threading.Thread.Sleep(500);
// timePassed += 500;
// }
// if (timePassed >= 3000)
// return false;
// }
// _dbIsBusy = true;
return true;
}
public static void finishDB()
{
// _dbIsBusy = false;
}
public static bool Connect()
{
_isOpen = false;
try { _connection.Open(); }
catch (Exception ex)
{
/*
StringBuilder builder = new StringBuilder();
string sMsg = ex.Message;
builder.Append("<script language='javascript'>");
sMsg = sMsg.Replace("\"", "'");
builder.Append("alert( \"" + sMsg + "\" );");
builder.Append("</script>");
HttpContext.Current.Response.Write(builder.ToString());
*/
HttpContext.Current.Response.Write(ex.Message);
return false;
}
//if (_connection.State != System.Data.ConnectionState.Open)
// return false;
_isOpen = true;
return true;
}
public static void Disconnect()
{
if (null != _connection)
_connection.Close();
_isOpen = false;
}
public static bool TestConnection()
{
bool result = Connect();
if (result)
Disconnect();
return result;
}
public static bool DatabaseSynchronizing()
{
DataTable dt = new DataTable();
int numRows = 0;
bool synchronizing = true;
if (GetData("select synchronizing from client_branch;", ref numRows, dt))
{
if (numRows > 0)
{
if (!GetBoolean(ref synchronizing, dt, 0, "synchronizing"))
{
synchronizing = true;
}
}
}
if (dt != null)
dt.Dispose();
return synchronizing;
}
public static void WaitUntilReady()
{
//bool available = false;
//while (!available)
//{
// available = !DatabaseSynchronizing();
// if (!available)
// System.Threading.Thread.Sleep(50);
//}
}
public static bool dbErrorContinue()
{
if (_gettingInput)
return false;
_gettingInput = true;
_userInput = System.Windows.Forms.DialogResult.None;
Disconnect();
do
{
// _userInput = SmartMessageBox.ShowRetryCancel("Network connection to the local branch server is down.");
} while (_userInput == System.Windows.Forms.DialogResult.Retry && !Connect());
_gettingInput = false;
return (_userInput == System.Windows.Forms.DialogResult.Retry);
}
public static string escapeSlashes(string command)
{
string result = "";
for (int i = 0; i < command.Length; i++)
{
if (command[i] == '\'')
{
result += "\\";
}
result += command[i];
}
return result;
}
public static bool SendSyncCommand(string command)
{
//return true;
return RunCommand("insert into `update_queue` (command) values ('" + escapeSlashes(command) + "');", false);
}
public static bool RunCommand(string command, bool sync)
{
//if (!useDB())
// return false;
bool success = false;//, abort = false;
//while (!success && !abort)
//{
try
{
if (_isOpen == false)
{
Connect();
}
OdbcCommand c = _connection.CreateCommand();
c.CommandText = command;
c.CommandTimeout = 3;
c.CommandType = CommandType.Text;
c.ExecuteNonQuery();
success = true;
}
catch //(Exception e)
{
// SmartMessageBox.ShowMessage(e.GetType().ToString() + ": " + e.Message);
//if (!dbErrorContinue())
// abort = true;
}
finally
{
Disconnect();
}
//}
//finishDB();
if (!success)
return false;
if (sync)
{
// Add to list of updates to send
if (command.Length > 65535)
{
//SmartMessageBox.ShowMessage(
// "Error: This update is too large to be synchronized. " +
// "Please contact Vandoes Computer Systems and quote the following information:\n" +
// "'Update too large' - '" + command.Substring(0, 20) + "'");
}
else
{
SendSyncCommand(command);
}
}
_numQueries++;
return true;
}
public static bool RunCalculation(string command, ref object output)
{
//if (!useDB())
// return false;
bool success = false;//, abort = false;
//while (!success && !abort)
//{
try
{
if (_isOpen == false)
{
Connect();
}
OdbcCommand c = _connection.CreateCommand();
c.CommandText = command;
c.CommandTimeout = 3;
c.CommandType = CommandType.Text;
output = c.ExecuteScalar();
success = true;
}
catch (Exception e)
{
// SmartMessageBox.ShowMessage(e.GetType().ToString() + ": " + e.Message);
// if (!dbErrorContinue())
// abort = true;
}
finally
{
Disconnect();
}
//}
//finishDB();
if (!success)
return false;
if (output is DBNull)
return false;
_numQueries++;
return true;
}
public static bool GetData(string query, ref int numRows, DataTable dt)
{
//if (!useDB())
// return false;
bool success = false;//, abort = false;
//while (!success && !abort)
//{
try
{
if (_isOpen == false)
{
Connect();
}
OdbcCommand c = _connection.CreateCommand();
c.CommandText = query;
//c.CommandTimeout = 3;
c.CommandType = CommandType.Text;
OdbcDataAdapter da = new OdbcDataAdapter(c);
numRows = da.Fill(dt);
//da.Dispose();
success = true;
}
catch
{
//SmartMessageBox.ShowMessage(e.GetType().ToString() + ": " + e.Message);
//if (!dbErrorContinue())
// abort = true;
}
finally
{
Disconnect();
}
//}
//finishDB();
_numQueries++;
return success;
}
public static bool GetChar(ref char output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = '\0';
else
{
// Write Invalid data type to log file...
//if (!(data is string))
if (data.ToString() != "")
output = Convert.ToChar(data);
}
return true;
}
public static bool GetString(ref string output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = "";
else
{
// Write Invalid data type to log file...
//if (!(data is string))
output = Convert.ToString(data);
output.Replace("\\", "");
}
return true;
}
public static bool GetBlob(ref byte[] output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = null;
else
{
// Write Invalid data type to log file...
//if (!(data is byte[]))
if (data is byte[])
output = (byte[])data;
else
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' not of type 'blob'.");
return false;
}
}
return true;
}
/*
public static bool GetImage(ref Image output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
//SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
byte[] rawData = null;
MemoryStream myStream = null;
if (data is DBNull)
output = null;
else
{
// Write Invalid data type to log file...
//if (!(data is byte[]))
if (data is byte[])
{
// Get the image from bytes
rawData = (byte[])data;
if (rawData.Length == 0)
{
output = null;
return true;
}
try
{
myStream = new MemoryStream(rawData);
output = Bitmap.FromStream(myStream, true, true);
}
catch (Exception)
{
output = null;
// SmartMessageBox.ShowMessage("Error in database. Data in field '" + field + "' is not a valid image.");
return true;
}
}
else
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' not of type 'image'.");
return false;
}
}
return true;
}
*/
public static bool GetShort(ref short output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = -1;
else
{
// Write Invalid data type to log file...
//if (!(data is Int16))
output = Convert.ToInt16(data);
}
return true;
}
public static bool GetInt(ref int output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = -1;
else
{
// Write Invalid data type to log file...
//if (!(data is Int32))
output = Convert.ToInt32(data);
}
return true;
}
public static bool GetULong(ref ulong output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = 0;
else
{
// Write Invalid data type to log file...
//if (!(data is Decimal || data is Int64))
output = Convert.ToUInt64(data);
}
return true;
}
public static bool GetLong(ref long output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = -1;
else
{
// Write Invalid data type to log file...
//if (!(data is Int64))
output = Convert.ToInt64(data);
}
return true;
}
public static bool GetDouble(ref double output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = 0.00;
else
{
// Write Invalid data type to log file...
//if (!(data is Double))
output = Convert.ToDouble(data);
}
return true;
}
public static bool GetFloat(ref float output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = 0.0f;
else
{
// Write Invalid data type to log file...
//if (!(data is Single))
output = Convert.ToSingle(data);
}
return true;
}
public static bool GetDecimal(ref decimal output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = 0.00m;
else
{
// Write Invalid data type to log file...
//if (!(data is Decimal))
output = Convert.ToDecimal(data);
}
return true;
}
public static bool GetBoolean(ref bool output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = false;
else
{
// Write Invalid data type to log file...
//if (!(data is Int16))
output = Convert.ToBoolean(data);
}
return true;
}
public static bool GetDate(ref DateTime output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = DateTime.MinValue;
else
{
// Write Invalid data type to log file...
//if (!(data is DateTime))
if (data is DateTime)
output = (DateTime)data;
else
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' not of type 'date'.");
return false;
}
}
return true;
}
public static bool GetTime(ref TimeSpan output, DataTable dt, int row, string field)
{
DataColumn column = dt.Columns[field];
if (column == null)
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' does not exist.");
return false;
}
object data = dt.Rows[row][column];
if (data is DBNull)
output = TimeSpan.MinValue;
else
{
// Write Invalid data type to log file...
//if (!(data is TimeSpan))
if (data is TimeSpan)
output = (TimeSpan)data;
else
{
// SmartMessageBox.ShowMessage("Error in database. Field '" + field + "' not of type 'time'.");
return false;
}
}
return true;
}
}
}
![]() |
0 |
![]() |
Hi vivekkrish2001,
I suggest you to format your code well so that we can help you better.
From the error message, it's probably caused by the connection pool. If the connetions in the pool are not released in time, the following requests will be delayed. My suggestion is to check the connection pool and ensure each connection can be released in time.
Thanks.
David Qian
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |
Hi vivkey
Whenever open the connection, you have to check the niether connection is open or close. so you have to use the below code whenever open the connection.
if (Con.State=ConnectionState.open) Con.close();
Con.Open();
here Con is the Connection Objects. all the best for u task.
Thiru
Hope this help someone in the future
![]() |
0 |
![]() |
Hi Wencui, When you say format the code what do you mean? Sorry for that.. Regarding connection pool is concerned how will release the connections in time. If you see my connection objects are static in nature therefore there might be a case where a single connection is created and used again and again.. Thanks, Vivek
![]() |
0 |
![]() |
Hi Pathey,
I have even tried that but of no use.. this is my latest connect() function
public static bool Connect()
{
setDSN("vivek25_kirly");
// _isOpen = false;
try
{
if (_connection == null || _connection.State != ConnectionState.Open)
_connection.Open();
_isOpen = true;
return true;
}
catch (Exception ex)
{
HttpContext.Current.Response.Write(ex.Message);
// Disconnect();
return false;
}
}
![]() |
0 |
![]() |
Hi vivekkrish2001,
When you say format the code what do you mean?I just suggest you to post your source code in a good format so that we can read it easily. Otherwise, the code is not readable and it will get less replies. Please use the tool named "source code" in the right side of the panel when you compose the question. It can help you format the code well.
Regarding connection pool is concerned how will release the connections in time. If you see my connection objects are static in nature therefore there might be a case where a single connection is created and used again and againAre you sure the max number of the connections is big enough? Also, if some operation needs much time, you can think about use asynchronous connection. All of this is to keep more connections in the pool usable.
Thanks.
David Qian
Microsoft Online Community Support
Please remember to mark the replies as answers if they help and unmark them if they provide no help.
![]() |
0 |
![]() |