passwortgeschützte Access-Datenbank erstellen [gelöst]



  • Hi,

    ich erstelle mittels SQLConfigDataSource() eine leere Access-Datenbank und fülle diese später. Das funktioniert ohne Probleme. Ich habe lediglich das Problem, daß ich keinen Hinweis darauf finde, wie ich die Datenbank mit einem Passwort versehen kann.

    Ist dies mit meinem Weg überhaupt möglich?

    Ich hatte es schon versucht an die Attribute zu hängen mit PWD=test, aber dies blieb auch ohne Erfolg.



  • So ich habe nun etwas gefunden, was allerdings noch nicht super funktioniert.
    Ein Passwort wird gesetzt, aber wenn ich dann die Access direkt öffne und das Passwort bei der Eingabeaufforderung eingebe ist diese für Access nicht das korrekte Passwort.

    Hier mal ein Auszug aus meinem Code:

    int nResult = 0;
    	CDaoDatabase DaoDatabase;
    
    	try
    	{
    		DaoDatabase.Open(m_csPathDatabase, TRUE, FALSE, _T(";PWD=test"));
    	}
    	catch(CDaoException* pDaoException)
    	{
    		TRACE(_T("ERROR opening database!\n\tCode:%d,\n\tText:'%s'\n"),
    			pDaoException->m_pErrorInfo->m_lErrorCode,
    			pDaoException->m_pErrorInfo->m_strDescription
    			);
    		pDaoException->Delete();
    		nResult = -1;	//error
    	}
    
    	if (-1 != nResult)
    	{
    		try
    		{
    			BSTR szPasswordOld = csPasswordOld.AllocSysString();
    			BSTR szPasswordNew = csPasswordNew.AllocSysString();
    
    			DaoDatabase.m_pDAODatabase->NewPassword(szPasswordOld, szPasswordNew);
    		}
    		catch(CDaoException* pDaoException)
    		{
    			TRACE(_T("ERROR inserting into database!\n\tCode:%d,\n\tText:'%s'\n"),
    				pDaoException->m_pErrorInfo->m_lErrorCode,
    				pDaoException->m_pErrorInfo->m_strDescription
    				);
    			pDaoException->Delete();
    			nResult = -1;	//error
    		}
    
    		DaoDatabase.Close();
    	}
    


  • Problem gelöst...

    Man sollte auch kein Unicode-String als Passwort übergeben.

    Die Dokumentation dazu ist aber wirklich mal grottig.

    Man ersetze:

    BSTR szPasswordOld = csPasswordOld.AllocSysString();
    			BSTR szPasswordNew = csPasswordNew.AllocSysString();
    			DaoDatabase.m_pDAODatabase->NewPassword(szPasswordOld, szPasswordNew);
    

    mit:

    BSTR szPasswordOld = (BSTR)(LPCSTR)csPasswordOld;
    			BSTR szPasswordNew = (BSTR)(LPCSTR)csPasswordNew;
    			DaoDatabase.m_pDAODatabase->NewPassword(szPasswordOld, szPasswordNew);
    

Anmelden zum Antworten