关于服务器联接配置,代码求分析
关于服务器连接配置,代码求分析
void __fastcall TConfigure_Form::Button_TestClick(TObject *Sender)
{
char tpath[255];
String spath,tspath,kpath;
TIniFile *MyInt; //INI文件变量; (为什么需要新建一个INI文件来进行变更)
if (FileExists("server.INI"))
//检测有没有INI文件
{
GetWindowsDirectory(tpath,255); //获得系统路径
spath = StrPas(tpath); //char 转换为 String
tspath = ExtractFilePath(Application->ExeName); //获得当前路径
kpath = tspath+"\server.INI"; //设置INI文件名
MyInt = new TIniFile(ChangeFileExt( kpath, ".INI" ) ); //MYINT读取当前文件
MyInt->WriteString("Database","User ID",Edit_User->Text);
MyInt->WriteString("Database","Password",Edit_Password->Text);
MyInt->WriteString("Database","Data Source",Edit_Source->Text);
MyInt->WriteString("Database","Initial Catalog",Edit_Catalog->Text);
AnsiString str = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" + Edit_User->Text + ";" + "Password=" + Edit_Password->Text + ";Initial Catalog=" + Edit_Catalog->Text +";Data Source=" + Edit_Source->Text + ";";
Main_Form->SqlServerConn->Connected=false;
Main_Form->SqlServerConn->ConnectionString = str;
try
{
Main_Form->SqlServerConn->Connected = true;
ShowMessage("连接测试成功!");
}
catch(Exception *ex)
{
MessageBox(NULL,ex->Message.c_str(),"异常对话框",MB_OK);
}
delete MyInt;
MyInt = NULL;
}
else
{
MessageBox(NULL ,"找不文件server.ini 无法进行数据库连接配置!" ,"异常对话框" ,MB_OK);
} //检测有没有INI文件
}
void __fastcall TConfigure_Form::Button_TestClick(TObject *Sender)
{
char tpath[255];
String spath,tspath,kpath;
TIniFile *MyInt; //INI文件变量; (为什么需要新建一个INI文件来进行变更)
if (FileExists("server.INI"))
//检测有没有INI文件
{
GetWindowsDirectory(tpath,255); //获得系统路径
spath = StrPas(tpath); //char 转换为 String
tspath = ExtractFilePath(Application->ExeName); //获得当前路径
kpath = tspath+"\server.INI"; //设置INI文件名
MyInt = new TIniFile(ChangeFileExt( kpath, ".INI" ) ); //MYINT读取当前文件
MyInt->WriteString("Database","User ID",Edit_User->Text);
MyInt->WriteString("Database","Password",Edit_Password->Text);
MyInt->WriteString("Database","Data Source",Edit_Source->Text);
MyInt->WriteString("Database","Initial Catalog",Edit_Catalog->Text);
AnsiString str = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=" + Edit_User->Text + ";" + "Password=" + Edit_Password->Text + ";Initial Catalog=" + Edit_Catalog->Text +";Data Source=" + Edit_Source->Text + ";";
Main_Form->SqlServerConn->Connected=false;
Main_Form->SqlServerConn->ConnectionString = str;
try
{
Main_Form->SqlServerConn->Connected = true;
ShowMessage("连接测试成功!");
}
catch(Exception *ex)
{
MessageBox(NULL,ex->Message.c_str(),"异常对话框",MB_OK);
}
delete MyInt;
MyInt = NULL;
}
else
{
MessageBox(NULL ,"找不文件server.ini 无法进行数据库连接配置!" ,"异常对话框" ,MB_OK);
} //检测有没有INI文件
}
- 1控制excel的打印按钮替不可用
- 2用Mat定义的一幅图像显示在MFC的对话框上,不用Picture control 控件,如何做?多谢
- 3C++Builder XE8的WebBrowser加载文件会崩溃?解决方法
- 4~c++builder 一调试经常会死机,今天暴力关机10次了
- 5去PageControl的TabSheet1放按钮控件,有时放进去,有时放在Form上
- 6C++ Builder6怎么使用C#生成的COM lib(TLB)
- 7c++builder,如何把excl中的数据存储到一维数组中?数据如图
- 8c++Builder中怎么将AnsiString中的数赋值给字符串数组
- 9栈的顺序构造的基本操作
- 10何位配置XE7连接MAC开发iOS成功过