动态创建SQL Server数据库表存储过程
2007-11-11 11:27:25 来源:WEB开发网核心提示:strCn.Empty();strCn="provider=SQLOLEDB;data source="+server+";initial catalog="+db+";userID="+UserName+";Password="+Pwd;
strCn.Empty();
strCn="provider=SQLOLEDB;data source="+server
+";initial catalog="+db
+";userID="+UserName
+";Password="+Pwd;
_variant_t bcnstr=_variant_t(strCn);
_variant_t bunstr=_variant_t(UserName);
_variant_t bpwdstr=_variant_t(Pwd);
//打开一个连接
try
{
m_pConnection->Open(_bstr_t(bcnstr),_bstr_t(bunstr),
_bstr_t(bpwdstr),-1);//adOpenUnspecified
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("Warning: 连接数据库发生异常. 错误信息: %s; 文件: %s; 行: %d\n", e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(errormessage);
}
catch(...)
{
AfxMessageBox("Warning :连接数据库时发生未知错误");
}
}
strCn="provider=SQLOLEDB;data source="+server
+";initial catalog="+db
+";userID="+UserName
+";Password="+Pwd;
_variant_t bcnstr=_variant_t(strCn);
_variant_t bunstr=_variant_t(UserName);
_variant_t bpwdstr=_variant_t(Pwd);
//打开一个连接
try
{
m_pConnection->Open(_bstr_t(bcnstr),_bstr_t(bunstr),
_bstr_t(bpwdstr),-1);//adOpenUnspecified
}
catch(_com_error e)
{
CString errormessage;
errormessage.Format("Warning: 连接数据库发生异常. 错误信息: %s; 文件: %s; 行: %d\n", e.ErrorMessage(), __FILE__, __LINE__);
AfxMessageBox(errormessage);
}
catch(...)
{
AfxMessageBox("Warning :连接数据库时发生未知错误");
}
}
void smsLogon::ExitDB() //退出时关闭数据库连接
{
if(m_pConnection!=NULL)
{
m_pConnection->Close();//关闭连接
m_pConnection.Release();//释放对象
}
}
[]
赞助商链接