I try to connect to a oracle database, where server is installed on my laptop and run on port 1521 and the name is "orcl". First, I connect using Java and jdbc using this code:
private static final String URL = "jdbc:oracle:thin:@localhost:1521:orcl";
private static final String USERNAME = "cosmin";
private static final String PASSWORD = "123456";
private static Connection conn;
conn = DriverManager.getConnection(URL, USERNAME, PASSWORD);
And now I try to connect using MFC and using CDatabase class but I can't connect.
CDatabase db;
TRY{
db.OpenEx(L"ODBC;DRIVER={MICROSOFT ODBC FOR ORACLE};DSN=orcl;SERVER=@localhost:1521:orcl;UID=cosmin; PWD=123456");
db.Close();
} CATCH(CDBException, e) {
AfxMessageBox(L"Database error: " + e->m_strError);
}
I receive the next error: Datasource name not found and no default driver specified. How can I resolve this problem?
Thanks!
If you are going to us a
data source name
. Here is how to get to the tool.And if you want to add the name in your program:
On the other hand, (I have not tried it), you should be able to use a DSN-less connection string. But that means you can't
DSN=orcl;
as there is no such DSN.