在本地插入数据库中,我运行5000次插入中间不会出现问题,但是如果是换成远程控制插入数据库,则只能运行到1316次的时候就提示不能建立连接了。请问是什么原因?怎么设置mysql???请老师指点一下。
解决方案 »
- 关于mysql5.6对于子查询的优化
- .net连接mysql编码问题
- 请求各位高人,postgreSQL 中 to_number()函数用法
- 计算两时间相差的秒数?
- Postgresql 中是否存在 Merge into 语法?
- 您能帮我解决吗?mysql 自表关联 外键约束 插入数据问题
- 求助,关于显示乱码的问题
- 请问怎样判断使用什么索引
- mysql里的字段类型是DATETIME,字段内容是包括日期和时间的 就是这样的 2004-8-15 17:12:07 的,我如何得到 2004-8-15
- 为什么MySql数据库中模糊查询一个汉字的时候得出的结果不对?
- 怎么样让MYSQL少改动?
- 存储过程
void DBDialog::Test()
{
m_comboBox3->Append( wxT("TXT.txt") );
m_comboBox3->SetSelection(0);
wxDbConnectInf *DbConnectInf = NULL; // 定义数据库连接信息指针DB connection information
wxDb *Conn = NULL; // 定义数据库连接指针Database connection
wxDbTable *table = NULL; // 定义数据表指针Data table to mysql
DbConnectInf = new wxDbConnectInf(0, wxT(""), wxT(""), wxT(""));//这里定义的内容基本没用,但不定义会报错
Conn = new wxDb(DbConnectInf->GetHenv());
bool DBfailOnDataTypeUnsupported=!true;// if(!Conn->Open(wxT("driver={mysql odbc 5.1 driver};server=192.168.100.13;DSN=icdata_db;charset=gb2312;database=icdata_db;uid=root;pwd=duangexin;port=3306;"),DBfailOnDataTypeUnsupported))//使用驱动程序的方式打开数据库
{
wxMessageBox("不能建立连接!","DB CONNECTION ERROR", wxOK | wxICON_EXCLAMATION);
wxDbFreeConnection(Conn);
DbConnectInf->FreeHenv();
return ;
} table = new wxDbTable(Conn, wxT("ictable"),10,wxT(""),!wxDB_QUERY_ONLY, wxT("")); //定义保存列内容的变量
wxString sst;
wxChar ChipNumbers[100];
wxChar ChipCounts[100];
wxChar ChipTypes[100];
wxChar InspectorNumbers[100];
wxChar CheckTimes[100];
wxChar BugTypes[100];
wxChar CheckItems[100];
wxChar CheckResults[100];
wxChar ErrorCounts[100];
wxChar ErrorPercents[100];
//有几列就定义几列
table->SetColDefs(0, wxT("ChipNumber"), DB_DATA_TYPE_VARCHAR,ChipNumbers, SQL_C_WXCHAR, sizeof(ChipNumbers), true, true);
table->SetColDefs(1, wxT("ChipCount"), DB_DATA_TYPE_VARCHAR, ChipCounts,SQL_C_WXCHAR, sizeof(ChipCounts), true, true);
table->SetColDefs(2,wxT("ChipType"),DB_DATA_TYPE_VARCHAR,ChipTypes,SQL_C_WXCHAR,sizeof(ChipTypes),true,true);
table->SetColDefs(3, wxT("InspectorNumber"), DB_DATA_TYPE_VARCHAR,InspectorNumbers, SQL_C_WXCHAR, sizeof(InspectorNumbers), true, true);
table->SetColDefs(4, wxT("CheckTime"), DB_DATA_TYPE_VARCHAR, CheckTimes,SQL_C_WXCHAR, sizeof(CheckTimes), true, true);
table->SetColDefs(5,wxT("BugType"),DB_DATA_TYPE_VARCHAR,BugTypes,SQL_C_WXCHAR,sizeof(BugTypes),true,true);
table->SetColDefs(6, wxT("CheckItem"), DB_DATA_TYPE_VARCHAR,CheckItems, SQL_C_WXCHAR, sizeof(CheckItems), true, true);
table->SetColDefs(7, wxT("CheckResult"), DB_DATA_TYPE_VARCHAR, CheckResults,SQL_C_WXCHAR, sizeof(CheckResults), true, true);
table->SetColDefs(8,wxT("ErrorCount"),DB_DATA_TYPE_VARCHAR,ErrorCounts,SQL_C_WXCHAR,sizeof(ErrorCounts),true,true);
table->SetColDefs(9, wxT("ErrorPercent"), DB_DATA_TYPE_VARCHAR,ErrorPercents, SQL_C_WXCHAR, sizeof(ErrorPercents), true, true); //打开DbTable对象
if( !table->Open())
{
wxMessageBox("不能打开数据库结构表!");
wxDELETE(table);
table = 0;
Conn->Close();
wxDbFreeConnection(Conn);
Conn = 0;
DbConnectInf->FreeHenv();
return;
}
//添加新记录
wxStrcpy(ChipNumbers, wxT("ccc")); //ChipNumbers所绑定的字段将添加一条记录
wxStrcpy(ChipCounts,wxT("aa"));
wxStrcpy(ChipTypes,wxT("aa"));
wxStrcpy(InspectorNumbers,wxT("aa"));
wxStrcpy(CheckTimes,wxT("2009-11-09"));
wxStrcpy(BugTypes,wxT("aa"));
wxStrcpy(CheckItems,wxT("32"));
wxStrcpy(CheckResults,wxT("false"));
wxStrcpy(ErrorCounts,wxT("32"));
wxStrcpy(ErrorPercents,wxT("32")); if(!table->Insert())
{
//判断添加是否成功
wxMessageBox("添加失败!");
wxDELETE(table);
table = 0;
Conn->Close();
wxDbFreeConnection(Conn);
Conn = 0;
DbConnectInf->FreeHenv();
return;
}
//提交更新数据库
table->GetDb()->CommitTrans(); //关闭DbTable对象
if(table)
{
wxDELETE(table);
table = 0;
}
//关闭连接
if(Conn)
{
Conn->Close();
wxDbFreeConnection(Conn);
Conn = NULL;
//wxDbCloseConnections();
}
//释放环境
wxDELETE(DbConnectInf);
//DbConnectInf->FreeHenv();
}
if(!Conn->Open(wxT("driver={mysql odbc 5.1 driver};server=192.168.100.13;DSN=icdata_db;charset=gb2312;database=icdata_db;uid=root;pwd=duangexin;port=3306;"),DBfailOnDataTypeUnsupported))//使用驱动程序的方式打开数据库
{
wxMessageBox("不能建立连接","DB CONNECTION ERROR", wxOK | wxICON_EXCLAMATION);
}也就是运行到一定数量的时候 就无法打开连接了?弹出对话框 不能建立连接。
max_user_connections | 0检查一下这两个变量然后再看一下状态。
show status like '%conn%';mysql> show status like '%conn%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| Aborted_connects | 0 |
| Connections | 3 |
| Max_used_connections | 2 |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_finished_connects | 0 |
| Threads_connected | 2 |
+--------------------------+-------+
7 rows in set (0.00 sec)
老师这个max_connections | 100
max_user_connections | 0 mysql> show variables like '%connect%';
+--------------------------+-------------------+
| Variable_name | Value |
+--------------------------+-------------------+
| character_set_connection | gb2312 |
| collation_connection | gb2312_chinese_ci |
| connect_timeout | 10 |
| init_connect | |
| max_connect_errors | 10 |
| max_connections | 100 |
| max_user_connections | 0 |
+--------------------------+-------------------+
7 rows in set (0.08 sec)
Enter password: *********
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 22623
Server version: 5.1.32-community MySQL Community Server (GPL)Type 'help;' or '\h' for help. Type '\c' to clear the buffer.mysql> show status like '%conn%';
+--------------------------+-------+
| Variable_name | Value |
+--------------------------+-------+
| Aborted_connects | 0 |
| Connections | 22624 |
| Max_used_connections | 4 |
| Ssl_client_connects | 0 |
| Ssl_connect_renegotiates | 0 |
| Ssl_finished_connects | 0 |
| Threads_connected | 2 |
+--------------------------+-------+
7 rows in set (0.06 sec)mysql>
| Max_used_connections | 4 |非常奇怪的数字!你的实际的最大并发访问只有 4 个!
应该你是用的连接池。你连接不成功应该不是MYSQL的限制,而是你这个连接池的限制。
老师为什么你用这个语句出来的跟我不一样???
我在本机插入数据库不会出错,但是远程访问就出错,是不是跟远程设置有关系?还是??
这个语句是显示你当前MYSQL数据库服务的状态,当然每台机都会有差别了。