954,206 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Run time error on my SQL database

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....

eranga262154
Junior Poster
185 posts since Sep 2007
Reputation Points: 32
Solved Threads: 2
 

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" ));
Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

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

eranga262154
Junior Poster
185 posts since Sep 2007
Reputation Points: 32
Solved Threads: 2
 

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

Here's a usefull link

Regards Niek

Nick Evan
Not a Llama
Moderator
10,112 posts since Oct 2006
Reputation Points: 4,142
Solved Threads: 403
 

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....

eranga262154
Junior Poster
185 posts since Sep 2007
Reputation Points: 32
Solved Threads: 2
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You