char *bla nur bis \0 abrufbar wie umgeht man das?



  • Hab mich jetzt grad nochmals ein bischen im MSDN rumgetrieben... Frage: Wieso wertest du den Rückgabewert von SQLConfigDataSource nicht aus wenns schon nicht funktioniert? Der dürfte bei der Diagnose hilfreich sein...



  • Ja stimmt steht in der MSDN

    LPCSTR lpszAttributes

    mit dem hab ich Probleme!
    Das erwartet er aber doch als String, wieso soll ich dann binär arbeiten, tut mir leid ich versteh es grad nicht.



  • Da steht noch mehr.



  • OK das schau ich mir morgen nochmal an, bin heute irgendwie nicht in der lage auch nur irgend ne kleinigkeit zu finden. Es soll heute nicht sein!
    Vielen Dank und bis morgen 😉



  • Also ich hab jetzt glaub alles über die Atributes raus gefunden. Ich nimm mal an du meinst das hier:

    [Input]
    List of attributes in the form of keyword-value pairs.

    Doch leider hab ich kein Plan wie keyword-value pairs aussehen. Des weiteren hab ich nur das hier gefunden:

    If a data source name is passed to ConfigDSN in lpszAttributes, ConfigDSN checks that the name is valid. If the data source name matches an existing data source name and hwndParent is null, ConfigDSN overwrites the existing name. If it matches an existing name and hwndParent is not null, ConfigDSN prompts the user to overwrite the existing name.

    If lpszAttributes contains enough information to connect to a data source, ConfigDSN can add the data source or display a dialog box with which the user can change the connection information. If lpszAttributes does not contain enough information to connect to a data source, ConfigDSN must determine the necessary information; if hwndParent is not null, it displays a dialog box to retrieve the information from the user.

    If ConfigDSN displays a dialog box, it must display any connection information passed to it in lpszAttributes. In particular, if a data source name was passed to it, ConfigDSN displays that name but does not allow the user to change it. ConfigDSN can supply default values for connection information not passed to it in lpszAttributes.



  • Der Abschnitt darüber, unter "Comments" ist erheblich spannender als der Abschnitt Adding a Datasource (o;

    Schliesslich steht ja auch bei ConfigDSN:

    msdn schrieb:

    lpszAttributes
    [Input]
    List of attributes in the form of keyword-value pairs. For information about the list structure, see "Comments."

    Aber du bist schon verdammt nahe dran (o;



  • OK jetzt hab ich die Comments gelesenund hab das ganze mal ein wenig umgebaut.
    [cpp]CString DB_Parameter ="";
    DB_Parameter.Format("%s%s%s%s%s",DSN,DESCRIPTION,FILETYPE,Pfad,SCANROWS);
    CString sDsn = "";
    sDsn.Format("%s",DSN);
    if(SQLValidDSN(sDsn))//Aber hier geht er nicht rein, obwohl DSN DOK ist!
    SQLConfigDataSource(NULL,ODBC_ADD_SYS_DSN,ODBCDRIVER,DB_Parameter);
    }
    Hier mein ganzer Parameter-String

    {"DSN=Dok\0Description=Dok\0FileType=Access\0DBQ=H:\AV\OA_TEST\ADMIN\Tools\Dokumentenverwaltung_Arbeitsanweisung\Kopie_DokumentenVerwaltung.mdb\0MaxScanRows=20\0\0"}

    Das passt jetzt aber eigentlich scho!
    Aber es geht nicht!



  • Ich hasse zwar selbstzitate, aber...

    junix schrieb:

    Frage: Wieso wertest du den Rückgabewert von SQLConfigDataSource nicht aus wenns schon nicht funktioniert? Der dürfte bei der Diagnose hilfreich sein...

    Denn "Es geht nicht" ist keine gültige Fehlerbeschreibung, geschweige denn eine Fehlermedung die ich schonmal rigendwo gelesen hätte.



  • Rückgabewert von SqlConfigDatasource:

    Returns

    The function returns TRUE if it is successful, FALSE if it fails. If no entry exists in the system information when this function is called, the function returns FALSE.

    Joa der ist false!

    Ich nimm an du meinst ich soll noch *pfErrorCode auswerten, aber ich hab keine Ahnung wie ich an den ran komm. 😞



  • Polofreak schrieb:

    Ich nimm an du meinst ich soll noch *pfErrorCode auswerten, aber ich hab keine Ahnung wie ich an den ran komm. 😞

    Lies doch einfach mal die ganze Seite von oben bis unten durch. Natürlich ist der Abschnitt Diagnostics ebenso spannend, denn der Beginnt mit

    msdn.microsoft.com schrieb:

    When SQLConfigDataSource returns FALSE,

    ...

    [edit="junix"]Ahja, und um das gleich klar zu stellen: Nein, ich werde dir gar nichts vorkauen. Du wirst alles selbst lesen müssen (o;[/edit]



  • Huete bin ich in Codepostlaune

    Auslesen der INI.

    String CIniclass::getinifile(CString section,CString key,CString filename,CString direktory)
    {
    	AFX_MANAGE_STATE(AfxGetStaticModuleState());
    
    	if (direktory == "")
    	{
    		char *direkt = new char[5000];
    		int laenge = GetCurrentDirectory(4999,direkt);
    		direkt[laenge] = NULL;
    		direktory.Format("%s",direkt);
    		delete []direkt;
    	}
    	char *pBuf = new char[3000];
    	CString returnstring;
    	GetPrivateProfileString(section,key,"error",pBuf,3000,direktory + "\\" + filename);
    	returnstring.Format("%s",pBuf);
    	delete []pBuf;
    	return returnstring;
    }
    

    Klasse um eine Datasource zusammenzubauen

    class CSqlConfigString : public CStringArray
    {
        char *m_buffer;
        int m_iBufferSize;
    public:
        CSqlConfigString()
        {
    		m_buffer = NULL;
            m_iBufferSize = 0;
    
    	}
        ~CSqlConfigString()
        {
            delete[] m_buffer;
        }
    
        operator const char*() {
    			AFX_MANAGE_STATE(AfxGetStaticModuleState());
    
            int iSize = 0;
            for(int i=0;i<GetSize();i++)
                iSize += GetAt(i).GetLength()+1;
    
            if(iSize+1>m_iBufferSize)
            {
                       delete[] m_buffer;
                       m_buffer = new char [iSize+1];
                            m_iBufferSize=iSize+1;
            }
    
            char *ptr = m_buffer;
            for(int n=0;n<GetSize();n++)
            {
                strcpy(ptr,GetAt(n));
                ptr+=GetAt(n).GetLength();
                *ptr=0;++ptr;
            }
            *ptr = 0;
            return m_buffer;
        }
    };
    
    class CSqlConfigString : public CStringArray
    {
        char *m_buffer;
        int m_iBufferSize;
    public:
        CSqlConfigString()
        {
    		m_buffer = NULL;
            m_iBufferSize = 0;
    
    	}
        ~CSqlConfigString()
        {
            delete[] m_buffer;
        }
    
        operator const char*() {
    			AFX_MANAGE_STATE(AfxGetStaticModuleState());
    
            int iSize = 0;
            for(int i=0;i<GetSize();i++)
                iSize += GetAt(i).GetLength()+1;
    
            if(iSize+1>m_iBufferSize)
            {
                       delete[] m_buffer;
                       m_buffer = new char [iSize+1];
                            m_iBufferSize=iSize+1;
            }
    
            char *ptr = m_buffer;
            for(int n=0;n<GetSize();n++)
            {
                strcpy(ptr,GetAt(n));
                ptr+=GetAt(n).GetLength();
                *ptr=0;++ptr;
            }
            *ptr = 0;
            return m_buffer;
        }
    };
    

    Impl.

    bool CODBCDatabase::addorremovedsn(const CString & dsnname, const CString & treibername, const CString & datei, bool add)
    {
    
    //SQLConfigDataSource(NULL,ODBC_ADD_DSN, "Excel Files (*.xls)", 
    //                   "DSN=New Excel Data Source\0" 
    //                   "Description=New Excel Data Source\0" 
    //                   "FileType=Excel\0" 
    //                   "DataDirectory=C:\\EXCELDIR\0" 
    //                   "MaxScanRows=20\0");
    
    	CString treibernamen("");
    	CSqlConfigString dsn;
    	dsn.Add("DSN="+dsnname);
    
    	if(treibername == "ACCESS")
    	{
    		if(datei.IsEmpty())
    		{
    			CFileDialog fileDlg( true, NULL, NULL, NULL , "Kommaseparierte Datei (*.mdb)|*.mdb|");
    			if( fileDlg.DoModal ()==IDOK )
    			{
    				dsn.Add("DBQ="+fileDlg.GetPathName());
    				SetCurrentDirectory(GetApplicationDirectory());
    			}
    			else
    			{
    				return false;
    			}
    		}
    		else
    		{
    			dsn.Add("DBQ="+datei);
    		}
    		treibernamen = "Microsoft Access-Treiber (*.mdb)";
    	}
    	if(treibername == "EXCEL")
    	{
    		dsn.Add("FileType=Excel");
    		dsn.Add("DataDirectory="+datei);
    		treibernamen = "Excel Files (*.xls)";
    	}
    
    	const char* pSAttributes = (const char*)dsn;
    
    	if(add)
    	{
            if(SQLConfigDataSource(NULL, ODBC_ADD_SYS_DSN,treibernamen,pSAttributes) == 0) return false;
    
    	}
    	else
    	{
            if(SQLConfigDataSource(NULL, ODBC_REMOVE_SYS_DSN,treibernamen,pSAttributes) == 0) return false;
    	}
    
    	return true;
    }
    


  • Boah wie geil ist das denn?? 😮
    PERFEKT! 😃

    Ein riesen fettes Dankeschön an junix und UNIX-Tom! Ihr seid echt klasse.

    @junix P.S.: Natütlich hab ich mir SQLInstallerError auch durch gelsen, aber da waren einfach zu viele Fragen! Woher weiß ich was ich hier wählen muss
    iError

    [Input]
    Error record number. Valid numbers are from 1 to 8.
    ... drum, ich hab wirklich kein Plan wie ich an den Error komm. Aber UNIX-Tom hat mir ja alles perfekt gepostet!

    VIELEN DANK!


Anmelden zum Antworten