我是自动附加数据库的,
m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);
不知道是怎么回事,
前面的一些代码:
char buf[256];//
::GetCurrentDirectory(256,buf);//获取根目录路径
strcat(buf,"\\student_Data.mdf");//
CString str,strlog,strmdf;
str="student";
strmdf=buf;
strlog=buf;
strlog.Replace("Data.mdf","Log.ldf");
CAdoxinView::OnAdoInitConn("master");//连接
CString sql;
sql.Format("EXEC sp_attach_db @dbname=N'%s',@filename1=N'%s',@filename2=N'%s'",str,strmdf,strlog);
try
{
m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
CAdoxinView::ExitAdoConn();
m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);
不知道是怎么回事,
前面的一些代码:
char buf[256];//
::GetCurrentDirectory(256,buf);//获取根目录路径
strcat(buf,"\\student_Data.mdf");//
CString str,strlog,strmdf;
str="student";
strmdf=buf;
strlog=buf;
strlog.Replace("Data.mdf","Log.ldf");
CAdoxinView::OnAdoInitConn("master");//连接
CString sql;
sql.Format("EXEC sp_attach_db @dbname=N'%s',@filename1=N'%s',@filename2=N'%s'",str,strmdf,strlog);
try
{
m_pConnection->Execute((_bstr_t)sql,NULL,adCmdText);
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}
CAdoxinView::ExitAdoConn();
{
CString strconn;//
try {
m_pConnection.CreateInstance(__uuidof(Connection));
strconn.Format("Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;\
Initial Catalog=%s;Data Source=.\\SQLEXPRESS",str);//连接字符串
m_pConnection->Open((_bstr_t)strconn,"","",adModeUnknown);//建立联结
}
catch(_com_error e)
{
AfxMessageBox(e.Description());
}}应该打开了啊
CString strconn;//设置连接字符串
strconn="Provider=SQLOLEDB;Data Source=local;Integrated Security=SSPI";//连接字符串
我是这样做的连接成功了的
echo 正在设置系统数据库,请稍候...
@odbcconf.exe /a {CONFIGSYSDSN "SQL Server" "DSN=CSGL|Description=汽车销售管理系统|SERVER=(local)|Database=CSGL"}
REG Delete "HKLM\SOFTWARE\ODBC\ODBC.INI\CSGL" /v "LastUser" /f
REG ADD "HKLM\SOFTWARE\ODBC\ODBC.INI\CSGL" /v "LastUser" /t "REG_SZ" /d "sa" /f
echo 系统数据库设置完成!
echo.