Thread: db.OpenEx

  1. #1
    Registered User
    Join Date
    Apr 2005
    Posts
    19

    db.OpenEx

    hi guys

    i have a new problem :|

    Code:
    void CDeploymentDlg::OnOK() 
    {
    	CString str;
    	CDatabase db;
    
    	try
    	{
    		db.OpenEx("DRIVER={Microsoft Access Driver(deployment.mdb)};DBQ=D:\\c_projekter\\deployment\\deployment.mdb", CDatabase::noOdbcDialog);
    
    		//("ODBC;Description=;DRIVER=SQL Server;SERVER=TPTEST"); 
    		//db.OpenEx("Driver = {Microsoft Access Driver(deployment.mdb)};DBQ=deployment.mdb");
    		//db.OpenEx("deployment.mdb");
    		//db.OpenEx("deployment.mdb", CDatabase::noOdbcDialog );
    		//db.OpenEx("Driver={Microsoft Access Driver (deployment.mdb)};DBQ=deployment.mdb;", CDatabase::noOdbcDialog);
    	}
    	catch(CDBException*)
    	{
    		AfxMessageBox("The database deployment.mdb was not found!!!", MB_ICONERROR);
    		exit(0);
    		throw;
    	}
    i have to manually select the data source to be access... anyone know how to make it do that automaticly ?

  2. #2
    train spotter
    Join Date
    Aug 2001
    Location
    near a computer
    Posts
    3,868
    >>i have to manually select the data source to be access
    You can create a DSN (Data Source Name) under Windows. It holds info on the DB (driver, location ect)
    [Administrative Tools -> Data Sources (ODBC)]

    Then use the DSN in the call to OpenEx()

    Code:
    //for DSN called MyDSN
    //sDB = "MyDSN"
    
    CString  sOpenDB;
    sOpenDB.Format("DSN=%s;UID=%s;PWD=%s;" ,sDB, sUserName ,sPassword);
    DB.OpenEx(sOpenDB, CDatabase::noOdbcDialog);
    I posted the code for a system DSN in the last thread. Can be used at run time so can be sure your app has an accurate DSN. Should work over network and local.
    "Man alone suffers so excruciatingly in the world that he was compelled to invent laughter."
    Friedrich Nietzsche

    "I spent a lot of my money on booze, birds and fast cars......the rest I squandered."
    George Best

    "If you are going through hell....keep going."
    Winston Churchill

Popular pages Recent additions subscribe to a feed