Hi all,

I create a database on SQL 2005 Express edition and link it to a C++/MFC application as follows. It wont gives any compile time errors. But at run time, it gives an error. Here are details.

Link the database in OnInitDialog()

here is the code

BOOL CSRFDBDlg::OnInitDialog()
{
CDatabase srfDB ;
CString srfNAME ;

srfNAME = "ODBC; DSN=.SQLEXPRESS; UID=sa; PWD=sa123; DATABASE=srfdb.mdf" ;
srfDB.Open(srfNAME) ;
if(srfDB.IsOpen())
{
AfxMessageBox("ok") ;
}

srfDB.Close() ;
}

Gives the following runtime error

Data source name not found and no default driver specified

Can you guys tell me where I'm going wrong....

hmm, are you calling that ' open' function the right way?

source: http://msdn2.microsoft.com/en-us/library/7ca7bkdw(VS.80).aspx

try calling it like:

CDatabase srfDB ;
srfDB.Open( _T( ".SQLEXPRESS" ), FALSE,  FALSE, _T( "UID=sa; PWD=sa123; DATABASE=srfdb.mdf" ));

Thanks, but I got the same error on that code as well.

And you're sure you got the DB and DNS set up correctly?

Here's a usefull link

Regards Niek

Yep, I'm sure that the DNS setup is correct. At the time I've tried the SQLOLEDB.1 connection. I think it can be easy to work on OLEDB, do you have any suggestion on that?

I'm really appreciate your comments....

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.