我有一个C#应用程序,它基本上为测试数据库生成大量数据。它使用的是Oracle.DataAccess版本4.112.3.0
出于某种奇怪的原因,每 30 次插入 OracleCommand.ExecuteNonQuery() 语句将持续几秒钟。在某些情况下,我们正在谈论15 秒!
通过 DSN 使用通用 ODBC 连接时,我没有遇到此问题。我无法返回使用 DSN,因为我希望此应用程序即使在没有安装 oracle 客户端的系统上也能正常工作。
非常感谢任何帮助
我的连接类的代码,处理打开连接并执行插入 - 设置适用于 SQLServer 和 Oracle
public Connection(string username,
string password,
string serverAddress,
String servicename,
string qual)
{
uid = username;
pwd = password;
server = serverAddress;
oraServiceName = servicename;
qualifier = qual;
string oradb = "Data Source=(DESCRIPTION="
+ "(ADDRESS=(PROTOCOL=TCP)(HOST=" + serverAddress + ")(PORT=1521))"
+ "(CONNECT_DATA=(SERVICE_NAME="+servicename+")));"
+ "User Id=" + username + ";Password=" + password + ";";
oraConn = new OracleConnection(oradb);
oraCom = new OracleCommand("",oraConn);
oraCom.CommandType = System.Data.CommandType.Text;
}
public void doInsert(string s)
{
try
{
sqlCom.CommandText = s;
sqlCom.Connection = sqlConn;
sqlCom.ExecuteNonQuery();
}
catch (NullReferenceException e)
{
try
{
oraCom.CommandText = s;
// oraCom.Connection = oraConn;
oraCom.ExecuteNonQuery();
}
catch (NullReferenceException e2)
{
throw e2;
}
}
}
实际插入的代码
public void generateData()
{
try
{
indivID = GenerateId();
conn.openConn();
conn.doInsert(tData.insertIndividual());
//number of calls
for (long x = 0; x < numCalls; x++)
{
countCalls++;
callidkey = GenerateId();
//start segments
for (long y = 0; y < numSegments; y++)
{
if (countSegs != numSegments)
{
countSegs++;
}
else
{
countSegs = 0;
}
INTX_ID = GenerateId();
conn.doInsert(this.tData.insertINTXSEGMENT());
//start parts and recordings
for (long n = 0; n < numParts; n++)
{
// INTX_PART_ID = GenerateId();
conn.doInsert(tData.insertINTXPART());
if (countParts != numParts)
{
countParts++;
}
else
{
countParts = 0;
}
if (genRec)
{
recData.recordingid = GenerateId();
conn.doInsert(recData.insertRecData());
conn.doInsert(recData.insertRecPart());
if (countRecs != numParts)
{
countRecs++;
}
else
{
countRecs = 0;
}
}
}
}
}
}
catch (Exception)
{}
}
}