Run time error on my SQL database

Please support our C++ advertiser: Intel Parallel Studio Home
Reply

Join Date: Sep 2007
Posts: 185
Reputation: eranga262154 is an unknown quantity at this point 
Solved Threads: 2
eranga262154's Avatar
eranga262154 eranga262154 is offline Offline
Junior Poster

Run time error on my SQL database

 
0
  #1
Oct 24th, 2007
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

  1. BOOL CSRFDBDlg::OnInitDialog()
  2. {
  3. CDatabase srfDB ;
  4. CString srfNAME ;
  5.  
  6. srfNAME = "ODBC; DSN=.SQLEXPRESS; UID=sa; PWD=sa123; DATABASE=srfdb.mdf" ;
  7. srfDB.Open(srfNAME) ;
  8. if(srfDB.IsOpen())
  9. {
  10. AfxMessageBox("ok") ;
  11. }
  12.  
  13. srfDB.Close() ;
  14. }


Gives the following runtime error
  1. Data source name not found and no default driver specified

Can you guys tell me where I'm going wrong....
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,833
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: Run time error on my SQL database

 
0
  #2
Oct 24th, 2007
hmm, are you calling that ' open' function the right way?

source: http://msdn2.microsoft.com/en-us/lib...dw(VS.80).aspx

try calling it like:

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

regards Niek
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 185
Reputation: eranga262154 is an unknown quantity at this point 
Solved Threads: 2
eranga262154's Avatar
eranga262154 eranga262154 is offline Offline
Junior Poster

Re: Run time error on my SQL database

 
0
  #3
Oct 24th, 2007
Thanks, but I got the same error on that code as well.
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Reply With Quote Quick reply to this message  
Join Date: Oct 2006
Posts: 2,833
Reputation: niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute niek_e has a reputation beyond repute 
Solved Threads: 297
Moderator
Featured Poster
niek_e's Avatar
niek_e niek_e is offline Offline
Roasting Maven

Re: Run time error on my SQL database

 
0
  #4
Oct 24th, 2007
And you're sure you got the DB and DNS set up correctly?

Here's a usefull link

Regards Niek
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 185
Reputation: eranga262154 is an unknown quantity at this point 
Solved Threads: 2
eranga262154's Avatar
eranga262154 eranga262154 is offline Offline
Junior Poster

Re: Run time error on my SQL database

 
0
  #5
Oct 24th, 2007
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....
“victory breeds hatred, the defeated live in pain; happily the peaceful live giving up victory and defeat” - Gautama Buddha
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the C++ Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC