I have found a solution, & this is a test code which uses the master db to create the test db
CDatabase masterdb;
masterdb.OpenEx(_T("DRIVER=SQL Server;DATABASE=master;Trusted_Connection=Yes;SERVER=(local)\\SQLEXPRESS"));
CString strCurrentDir;
::GetModuleFileName(NULL, strCurrentDir.GetBufferSetLength(_MAX_PATH), _MAX_PATH);
strCurrentDir.ReleaseBuffer();
strCurrentDir = strCurrentDir.Left(strCurrentDir.ReverseFind('\\') + 1);
CString strExec = _T("create database test on (name='test_data', filename = '") + strCurrentDir + _T("test_data.mdf')") +
_T("\nlog on (name='test_log', filename = '") + strCurrentDir + _T("test_log.ldf')");
TRY
{
masterdb.ExecuteSQL(strExec);
}
CATCH(CDBException, e)
{
TCHAR buff[1024];
e->GetErrorMessage(buff, 1024);
AfxMessageBox(buff);
e->Delete();
}
END_CATCH
masterdb.Close();
NB: you have to verify if the test db has been created before first (I am working around on this).