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();
A
handled Exception when reaching
masterdb.ExecuteSQL(strExec);
says:
CREATE FILE encountered operating system error 5(Access is denied.) while attempting to open or create the physical file 'C:\Program Files (x86)\Microsoft Visual Studio\MyProjects\master\Debug\test_data.mdf'.
CREATE DATABASE failed. Some file names listed could not be created.
Check related errors.
I don't know what it means.
Help me please.
Thank you for your understanding.