_variant_t strSQL;
CString strConnect;
//===================使用系统数据库========================================
::CoInitialize(NULL);
strC;//?Windows验证?
try
{
ADOConn.CreateInstance(__uuidof(Connection));
ADOConn->Open((const char *)strConnect,"","",adModeUnknown);//adConnectUnspecified
}
catch(...)
{
AfxMessageBox("数据库初始化错误,程序将关闭!");
return;
}
//初始化ADO记录集
m_pADOSet.CreateInstance(__uuidof(Recordset));
m_pADOSet->CursorLocation=adUseClient;
//创建数据库及数据库文件
strSQL="CREATE DATABASE MyTempDataBase ON PRIMARY (Name=MyTempDataBase_data, filename = 'd://MyTempDataBase.mdf', size=3, maxsize=5, filegrowth=10%) log on (name=MyTempDataBase_log,filename='d://MyTempDataBase.ldf',size=3, maxsize=20,filegrowth=1)";
m_pADOSet->Open(strSQL, ADOConn.GetInte***cePtr(), adOpenStatic, adLockOptimistic, adCmdUnknown);
// 释放ADO记录集
if(adStateOpen==m_pADOSet->State)
m_pADOSet->Close();
//释放ADO连接对象
if(adStateOpen == ADOConn->State)
ADOConn->Close();
//===============使用新创建的数据库=================================
strC;//?Windows验证?
try
{
ADOConn.CreateInstance(__uuidof(Connection));
ADOConn->Open((const char *)strConnect,"","",adModeUnknown);//adConnectUnspecified
}
catch(...)
{
AfxMessageBox("数据库初始化错误,程序将关闭!");
return;
}
//创建Person表及表结构
strSQL="CREATE TABLE Person(/
id INTEGER IDENTITY(1, 1) PRIMARY KEY NOT NULL,/
PersonName char(20) NULL ,/
Phone char(20) NULL ,/
Headship char(50) NULL)";
m_pADOSet->Open(strSQL, ADOConn.GetInte***cePtr(), adOpenStatic, adLockOptimistic, adCmdUnknown);
//创建newcomer表及表结构
strSQL="CREATE TABLE newcomer(/
id INTEGER IDENTITY(1, 1) PRIMARY KEY NOT NULL ,/
UserName char(20) NULL ,/
State char(10) NULL)";
m_pADOSet->Open(strSQL, ADOConn.GetInte***cePtr(), adOpenStatic, adLockOptimistic, adCmdUnknown);
// 释放ADO记录集
if(adStateOpen==m_pADOSet->State)
m_pADOSet->Close();
//释放ADO连接对象
if(adStateOpen == ADOConn->State)
ADOConn->Close();
CString strConnect;
//===================使用系统数据库========================================
::CoInitialize(NULL);
strC;//?Windows验证?
try
{
ADOConn.CreateInstance(__uuidof(Connection));
ADOConn->Open((const char *)strConnect,"","",adModeUnknown);//adConnectUnspecified
}
catch(...)
{
AfxMessageBox("数据库初始化错误,程序将关闭!");
return;
}
//初始化ADO记录集
m_pADOSet.CreateInstance(__uuidof(Recordset));
m_pADOSet->CursorLocation=adUseClient;
//创建数据库及数据库文件
strSQL="CREATE DATABASE MyTempDataBase ON PRIMARY (Name=MyTempDataBase_data, filename = 'd://MyTempDataBase.mdf', size=3, maxsize=5, filegrowth=10%) log on (name=MyTempDataBase_log,filename='d://MyTempDataBase.ldf',size=3, maxsize=20,filegrowth=1)";
m_pADOSet->Open(strSQL, ADOConn.GetInte***cePtr(), adOpenStatic, adLockOptimistic, adCmdUnknown);
// 释放ADO记录集
if(adStateOpen==m_pADOSet->State)
m_pADOSet->Close();
//释放ADO连接对象
if(adStateOpen == ADOConn->State)
ADOConn->Close();
//===============使用新创建的数据库=================================
strC;//?Windows验证?
try
{
ADOConn.CreateInstance(__uuidof(Connection));
ADOConn->Open((const char *)strConnect,"","",adModeUnknown);//adConnectUnspecified
}
catch(...)
{
AfxMessageBox("数据库初始化错误,程序将关闭!");
return;
}
//创建Person表及表结构
strSQL="CREATE TABLE Person(/
id INTEGER IDENTITY(1, 1) PRIMARY KEY NOT NULL,/
PersonName char(20) NULL ,/
Phone char(20) NULL ,/
Headship char(50) NULL)";
m_pADOSet->Open(strSQL, ADOConn.GetInte***cePtr(), adOpenStatic, adLockOptimistic, adCmdUnknown);
//创建newcomer表及表结构
strSQL="CREATE TABLE newcomer(/
id INTEGER IDENTITY(1, 1) PRIMARY KEY NOT NULL ,/
UserName char(20) NULL ,/
State char(10) NULL)";
m_pADOSet->Open(strSQL, ADOConn.GetInte***cePtr(), adOpenStatic, adLockOptimistic, adCmdUnknown);
// 释放ADO记录集
if(adStateOpen==m_pADOSet->State)
m_pADOSet->Close();
//释放ADO连接对象
if(adStateOpen == ADOConn->State)
ADOConn->Close();