[Webinar] Streamline your web hosting managementRegister Today

x
?
Solved

want to avoid opening odbcdialogbox

Posted on 2000-02-08
14
Medium Priority
?
209 Views
Last Modified: 2013-11-20
Hi!
I have written this code
            CDatabase db;
            CRecordset rec;
            int reccount;
            

            if(db.Open(_T("abc"),FALSE,FALSE,_T("ODBC;"),TRUE)!=0)
                  AfxMessageBox("connected",NULL,MB_OK);
            else
            AfxMessageBox("not connected",NULL,MB_OK);

            
//rec.m_pDatabase = &db;
rec.Open(CDatabase::dyna,_T( "Select * from xyz"));
            
            while(!rec.IsEOF())
            {
                  rec.MoveNext();
            }
            
            reccount=rec.GetRecordCount();
            printf("count = %d",reccount);

I am using SQL-Server7.0 on Win-NT.
Now in this code why is it opening an ODBCdialogBox for selecting the DSN name. If I wanna get rid of that dialogbox and want to hardcore my DSN name how do I do it?
After executing it should directly print the number of records.
There should not be any user interaction.
Thanks.
0
Comment
Question by:highmarks
  • 5
  • 3
  • 2
  • +3
14 Comments
 
LVL 2

Author Comment

by:highmarks
ID: 2499451
oh ya please do not give me answers like use option noodbcdialogbox since I have used them still it is opening the dialog box.
0
 

Expert Comment

by:krisp
ID: 2499484
Hi,
 With MS-ACCESS I am not getting this problem. So it might be something related to SQL Server

cheers.
0
 
LVL 4

Expert Comment

by:inpras
ID: 2499493
Hi
use SQLCOnfigureDataSource to configure data source prgrammatically
or cofnfigure the dta source in ODBC as abc U won't get the Dialog box
and also check UR not giving any password and login
When U specify a DSN name which is not configured then ODBC dialog box pops up

Hope this helps
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 1

Expert Comment

by:wildy
ID: 2499503
try to replace the _T("ODBC;") parameter with _T("ODBC;UID=sa")

Note: if sa have a password you must also specify the password.
0
 
LVL 2

Author Comment

by:highmarks
ID: 2499546
inprass can u give some code which can be used
0
 
LVL 2

Author Comment

by:highmarks
ID: 2499564
inprass can u give some code which can be used
0
 
LVL 4

Expert Comment

by:inpras
ID: 2499613
For Configuring
SQLConfigDataSource(NULL,ODBC_ADD_DSN, "Excel Files (*.xls)",
                   "DSN=New Excel Data Source\0"
                   "Description=New Excel Data Source\0"
                   "FileType=Excel\0"
                   "DataDirectory=C:\\EXCELDIR\0"
                   "MaxScanRows=20\0");

For opening
m_dbCust.Open( _T( "MYDATASOURCE" ), FALSE,
               FALSE, _T( "ODBC;UID=JOES;PWD=MyPSWD" ),TRUE);

U can use same for SQL-server only supply proper driver
Hope this helps
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 2500289
Call OpenEx() like so:

db.OpenEx("DSN=MYDATASOURCE;UID=sa",
 CDatabase::noOdbcDialog);

You may also or in openExclusive, openReadOnly, useCursorLib.

Good Luck,
Steve
0
 
LVL 2

Author Comment

by:highmarks
ID: 2502968
HI! Steve I had written it in my question that I have tried option of noodbcdialog but didn't help.
0
 
LVL 2

Author Comment

by:highmarks
ID: 2503312
guys I have tried options like SQLConfigDataSource and SQLDriverConnect. But it still asks me to select DSN name by opening ODBCDialogBox.
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 2504381
So you've tried OpenEx with the noOdbcOption and it still opened the dialog box? If you haven't I'd give it a try...

Good Luck,
Steve
0
 

Accepted Solution

by:
bertp earned 100 total points
ID: 2536752
Here is what worked for me

1) I did not explicitly open the database; I passed NULL to the CRecordset constructor, and the constructor constructed a CDatabase object for me;

2) I derived a class from CRecordset
  and overrode the GetDefaultConnect()
like this

CString CMySet::GetDefaultConnect()
{
return _T("ODBC;DSN=MYDSNENTRY");
}

(It has been awhile, but if I recall correctly, ClassWizard makes it easy to setup a CRecordset derived class specific to your own Database)


3)and obvisiouly, this assumes that you have previously set a MYDSNENTRY in the ODBC applet to point to a specific database...  Thats it... good luck!  
0
 

Expert Comment

by:bertp
ID: 2558489
Hi
  If you're still having trouble you should consider rejecting my answer so that you can again get help from others
Good Luck!
0
 
LVL 30

Expert Comment

by:SteveGTR
ID: 2558539
highmarks have you tried OpenEx() as annotated is my solution? Your initial example using Open(). I see where you made the comment about using the noodbcdialogbox, but not any code that uses it. If you are using this option how did you specify it (in code)?
0

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction: Hints for the grid button.  Nested classes, templated collections.  Squash that darned bug! Continuing from the sixth article about sudoku.   Open the project in visual studio. First we will finish with the SUD_SETVALUE messa…
If you use Adobe Reader X it is possible you can't open OLE PDF documents in the standard. The reason is the 'save box mode' in adobe reader X. Many people think the protected Mode of adobe reader x is only to stop the write access. But this fe…
This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
This video tutorial shows you the steps to go through to set up what I believe to be the best email app on the android platform to read Exchange mail.  Get the app on your phone: The first step is to make sure you have the Samsung Email app on your …
Suggested Courses

590 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question