Click here to Skip to main content
15,890,438 members
Home / Discussions / C / C++ / MFC
   

C / C++ / MFC

 
AnswerRe: CPoint's x and y has large value Pin
Cedric Moonen1-Apr-09 22:07
Cedric Moonen1-Apr-09 22:07 
GeneralRe: CPoint's x and y has large value Pin
nayeemkhan1-Apr-09 23:22
nayeemkhan1-Apr-09 23:22 
GeneralRe: CPoint's x and y has large value Pin
Niklas L2-Apr-09 3:02
Niklas L2-Apr-09 3:02 
GeneralRe: CPoint's x and y has large value Pin
David Crow2-Apr-09 3:47
David Crow2-Apr-09 3:47 
AnswerRe: CPoint's x and y has large value Pin
Code-o-mat1-Apr-09 22:42
Code-o-mat1-Apr-09 22:42 
AnswerRe: CPoint's x and y has large value Pin
krmed2-Apr-09 0:43
krmed2-Apr-09 0:43 
QuestionRe: CPoint's x and y has large value Pin
David Crow2-Apr-09 3:45
David Crow2-Apr-09 3:45 
QuestionHow to create a secure database with the MS-Jet ODBC driver [modified] Pin
pani681-Apr-09 20:35
pani681-Apr-09 20:35 
To create a secured MS Access database programmatically using MFC I followed the procedure described at http://www.litwindow.com/Knowhow/HowTo/howto_create_secure_access_dat.html[^]. I have incorporated the code in one of my functions. However, while granting privileges to the newly created group exception is thrown and I am not able to create the database. The function in which I am using the code is as below.

void CSecuredAccessDlg::OnBnClickedOk()
{
	if(m_fileName.IsEmpty())
	{
		MessageBox("No file selected!",NULL,MB_ICONERROR);
		return;
	}

	CString strConfig,sSql;
	CString strAccessDriver;
	CDatabase database;

	strAccessDriver="Microsoft Access Driver (*.mdb)";

	if(_access("my workgroup.mdw",0)==0)//	If the work group file exists, delete it
		unlink("my workgroup.mdw");
	if(_access(m_fileName,0)==0)		//	If the database file exists, delete it
		unlink(m_fileName);

	strConfig.Format("CREATE_SYSDB=\"my workgroup.mdw\"\0\0");
	SQLConfigDataSource(NULL, ODBC_ADD_DSN, strAccessDriver,strConfig);

	strConfig.Empty();
	strConfig.Format("CREATE_DB=\"%s\"\0\0",m_fileName);
	SQLConfigDataSource(NULL, ODBC_ADD_DSN, strAccessDriver,strConfig);

	strConfig.Empty();
	TRY
	{
		strConfig.Format("DRIVER={%s};DSN='';READONLY=FALSE;"
			"CREATE_DB=\"%s\";DBQ=%s;SystemDB=%s;UID=admin;"
			"ExtendedAnsiSQL=1",strAccessDriver,m_fileName,m_fileName,
			"my workgroup.mdw");
		if(database.OpenEx(strConfig,CDatabase::noOdbcDialog))
		{
			sSql.Format("CREATE GROUP %s %s","Administrators","1234ABC");
			database.ExecuteSQL(sSql);
			
			sSql.Empty();
			sSql.Format("CREATE USER %s \"%s\" %s","Pani","","1234DEF");
			database.ExecuteSQL(sSql);

			//	Add user to the group created
			sSql.Empty();
			sSql.Format("ADD USER %s TO %s","Pani","Administrators");
			database.ExecuteSQL(sSql);

			//	Add user to the the admins group
			sSql.Empty();
			sSql.Format("ADD USER %s TO %s","Pani","admins");
			database.ExecuteSQL(sSql);

			database.Close();
			unlink(m_fileName);

			strConfig.Empty();
			strConfig.Format("CREATE_DB=\"%s\"\0SystemDB=my workgroup.mdw"
							"\0UID=Pani\0\0",m_fileName);
			SQLConfigDataSource(NULL, ODBC_ADD_DSN, strAccessDriver,strConfig);

			strConfig.Format("DRIVER={%s};DSN='';READONLY=FALSE;"
				"CREATE_DB=\"%s\";DBQ=%s;SystemDB=%s;UID=Pani;ExtendedAnsiSQL=1",
				strAccessDriver,m_fileName,m_fileName,"my workgroup.mdw");

			if(database.OpenEx(strConfig))
			{
				sSql.Format("GRANT ALL PRIVILEGES ON DATABASE TO Administrators");
				database.ExecuteSQL(sSql); // Exception occurs here :mad:

				sSql.Format("REVOKE ALL PRIVILEGES ON DATABASE FROM admin");
				database.ExecuteSQL(sSql);

				sSql.Format("REVOKE ALL PRIVILEGES ON DATABASE FROM admins");
				database.ExecuteSQL(sSql);

				sSql.Format("REVOKE ALL PRIVILEGES ON DATABASE FROM users");
				database.ExecuteSQL(sSql);

				//	Alter the user password to pani
				sSql.Format("ALTER USER Pani PASSWORD %s \"%s\"","pani123","");
				database.ExecuteSQL(sSql);

				FillData(&database);
				database.Close();
			}

		}
	}
	CATCH(CDBException, e)
	{
		if(database.IsOpen())
			database.Close();
		MessageBox(e->m_strError,NULL,MB_ICONERROR);
		return;
	}
	END_CATCH
}


Can anyone provide suggestions for correcting the code?

Thanks in advance.

Pani68

modified on Thursday, April 2, 2009 3:32 AM

AnswerRe: How to create a secure database with the MS-Jet ODBC driver [modified] Pin
Stuart Dootson1-Apr-09 22:43
professionalStuart Dootson1-Apr-09 22:43 
GeneralRe: How to create a secure database with the MS-Jet ODBC driver Pin
pani682-Apr-09 2:20
pani682-Apr-09 2:20 
GeneralRe: How to create a secure database with the MS-Jet ODBC driver Pin
Stuart Dootson2-Apr-09 2:22
professionalStuart Dootson2-Apr-09 2:22 
QuestionHow to convert const void* to CString? Pin
g_satish1-Apr-09 20:26
g_satish1-Apr-09 20:26 
AnswerRe: How to convert const void* to CString? Pin
«_Superman_»1-Apr-09 20:30
professional«_Superman_»1-Apr-09 20:30 
AnswerRe: How to convert const void* to CString? Pin
Stuart Dootson1-Apr-09 21:56
professionalStuart Dootson1-Apr-09 21:56 
QuestionHow to capture "Enter Key"? Pin
gothic_coder1-Apr-09 20:25
gothic_coder1-Apr-09 20:25 
AnswerRe: How to capture "Enter Key"? Pin
«_Superman_»1-Apr-09 20:32
professional«_Superman_»1-Apr-09 20:32 
GeneralRe: How to capture "Enter Key"? Pin
gothic_coder1-Apr-09 20:36
gothic_coder1-Apr-09 20:36 
AnswerRe: How to capture "Enter Key"? Pin
Code-o-mat1-Apr-09 22:32
Code-o-mat1-Apr-09 22:32 
GeneralRe: How to capture "Enter Key"? Pin
gothic_coder1-Apr-09 23:29
gothic_coder1-Apr-09 23:29 
GeneralRe: How to capture "Enter Key"? Pin
Code-o-mat1-Apr-09 23:33
Code-o-mat1-Apr-09 23:33 
GeneralRe: How to capture "Enter Key"? Pin
gothic_coder1-Apr-09 23:59
gothic_coder1-Apr-09 23:59 
GeneralRe: How to capture "Enter Key"? Pin
Code-o-mat2-Apr-09 0:20
Code-o-mat2-Apr-09 0:20 
GeneralRe: How to capture "Enter Key"? Pin
gothic_coder2-Apr-09 1:31
gothic_coder2-Apr-09 1:31 
GeneralRe: How to capture "Enter Key"? Pin
Code-o-mat2-Apr-09 1:34
Code-o-mat2-Apr-09 1:34 
QuestionCMainwindow Pin
p_19601-Apr-09 20:20
p_19601-Apr-09 20:20 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.