944,124 Members | Top Members by Rank

Ad:
  • C++ Discussion Thread
  • Unsolved
  • Views: 1579
  • C++ RSS
Oct 24th, 2007
0

Run time error on my SQL database

Expand Post »
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

c++ Syntax (Toggle Plain Text)
  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
C++ Syntax (Toggle Plain Text)
  1. Data source name not found and no default driver specified

Can you guys tell me where I'm going wrong....
Similar Threads
Reputation Points: 32
Solved Threads: 2
Junior Poster
eranga262154 is offline Offline
185 posts
since Sep 2007
Oct 24th, 2007
0

Re: Run time error on my SQL database

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:

C++ Syntax (Toggle Plain Text)
  1.  
  2. CDatabase srfDB ;
  3. srfDB.Open( _T( ".SQLEXPRESS" ), FALSE, FALSE, _T( "UID=sa; PWD=sa123; DATABASE=srfdb.mdf" ));
Last edited by Nick Evan; May 11th, 2010 at 8:40 am.
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Oct 24th, 2007
0

Re: Run time error on my SQL database

Thanks, but I got the same error on that code as well.
Reputation Points: 32
Solved Threads: 2
Junior Poster
eranga262154 is offline Offline
185 posts
since Sep 2007
Oct 24th, 2007
0

Re: Run time error on my SQL database

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

Here's a usefull link

Regards Niek
Moderator
Featured Poster
Reputation Points: 4142
Solved Threads: 394
Industrious Poster
Nick Evan is offline Offline
4,132 posts
since Oct 2006
Oct 24th, 2007
0

Re: Run time error on my SQL database

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....
Reputation Points: 32
Solved Threads: 2
Junior Poster
eranga262154 is offline Offline
185 posts
since Sep 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C++ Forum Timeline: Question
Next Thread in C++ Forum Timeline: Double Returning 1.#INF





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC