诸
诸葛白痴
Unregistered / Unconfirmed
GUEST, unregistred user!
兄弟们,有一个非常怪的问题,用ADOConnection,出问题:
1、读出原来存在注册表里的信息,写入ADOConnection.connectionstring
2、尝试连接,如果成功则登入自己的数据库,如果失败,跳出一个配置界面
3、根据配置界面的内容,重新写入ADOConnection.connnectionstring,再次连接,
可就是这出问题,比如原来连接数据库1(原注册表里的信息),失败后,如果在配置界面中
连接数据库2(新的),这时已经改写了adoconnection.connectionstring时了,可是好像
系统还是将ado连接数据库1,而不是connectionstring里的数据库2,只有程序结束,再
次重新连接数据库2就可以了,这是为什么?连接函数如下:
bool __fastcall _export ConnectToServer(AnsiString &UserName,AnsiString &Password,AnsiString &ServerName,AnsiString &DatabaseName)
{
AnsiString S_ConnectionString;
S_ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;/
Use Procedure for Prepare=1;Auto Translate=True;Tag with column collation when possible=False;";
S_ConnectionString = S_ConnectionString.Trim() + "User Id=" + UserName + ";";
S_ConnectionString = S_ConnectionString.Trim() + "Password=" + Password + ";";
S_ConnectionString = S_ConnectionString.Trim() + "Extended Properties='Server=" + ServerName + ";Database=" + DatabaseName + "'";
dt->m_Connection->KeepConnection = false;
dt->m_Connection->Connected = false;
dt->m_Connection->Close();
dt->m_Connection->KeepConnection = false;
dt->m_Connection->ConnectionString = S_ConnectionString;
dt->m_Connection->DefaultDatabase = DatabaseName;
//连接串完成
try
{
dt->m_Connection->ConnectionTimeout = 10;
dt->m_Connection->Connected = true;
dt->m_Connection->KeepConnection = true;
dt->m_Connection->CommandTimeout = 0;
dt->m_DataSet->CommandTimeout = 0;
dt->m_Command->CommandTimeout = 0;
S_ConnectionString = "use " + DatabaseName;
dt->m_Command->CommandText = S_ConnectionString;
dt->m_Command->Execute();
}
catch (...)
{
return false;
}
return true;
}
//---------------------------------------------------------------------------
流程如下:
GetUserPassword(v1,v2,v3,v3);//从注册表中取得信息
try
{
connecttoserver(v1,v2,v3,v4); //连接数据库1
}
catch(...)
{
//跳出配置界面
根据配置界面用户输入的信息,改写v1,v2,v3,v4
如这时用户已改成数据库2,可系统还是提示失败,即它不是连接数据库1,为什么?
}
有哪位仁兄碰到过?
1、读出原来存在注册表里的信息,写入ADOConnection.connectionstring
2、尝试连接,如果成功则登入自己的数据库,如果失败,跳出一个配置界面
3、根据配置界面的内容,重新写入ADOConnection.connnectionstring,再次连接,
可就是这出问题,比如原来连接数据库1(原注册表里的信息),失败后,如果在配置界面中
连接数据库2(新的),这时已经改写了adoconnection.connectionstring时了,可是好像
系统还是将ado连接数据库1,而不是connectionstring里的数据库2,只有程序结束,再
次重新连接数据库2就可以了,这是为什么?连接函数如下:
bool __fastcall _export ConnectToServer(AnsiString &UserName,AnsiString &Password,AnsiString &ServerName,AnsiString &DatabaseName)
{
AnsiString S_ConnectionString;
S_ConnectionString = "Provider=SQLOLEDB.1;Persist Security Info=False;/
Use Procedure for Prepare=1;Auto Translate=True;Tag with column collation when possible=False;";
S_ConnectionString = S_ConnectionString.Trim() + "User Id=" + UserName + ";";
S_ConnectionString = S_ConnectionString.Trim() + "Password=" + Password + ";";
S_ConnectionString = S_ConnectionString.Trim() + "Extended Properties='Server=" + ServerName + ";Database=" + DatabaseName + "'";
dt->m_Connection->KeepConnection = false;
dt->m_Connection->Connected = false;
dt->m_Connection->Close();
dt->m_Connection->KeepConnection = false;
dt->m_Connection->ConnectionString = S_ConnectionString;
dt->m_Connection->DefaultDatabase = DatabaseName;
//连接串完成
try
{
dt->m_Connection->ConnectionTimeout = 10;
dt->m_Connection->Connected = true;
dt->m_Connection->KeepConnection = true;
dt->m_Connection->CommandTimeout = 0;
dt->m_DataSet->CommandTimeout = 0;
dt->m_Command->CommandTimeout = 0;
S_ConnectionString = "use " + DatabaseName;
dt->m_Command->CommandText = S_ConnectionString;
dt->m_Command->Execute();
}
catch (...)
{
return false;
}
return true;
}
//---------------------------------------------------------------------------
流程如下:
GetUserPassword(v1,v2,v3,v3);//从注册表中取得信息
try
{
connecttoserver(v1,v2,v3,v4); //连接数据库1
}
catch(...)
{
//跳出配置界面
根据配置界面用户输入的信息,改写v1,v2,v3,v4
如这时用户已改成数据库2,可系统还是提示失败,即它不是连接数据库1,为什么?
}
有哪位仁兄碰到过?