| |

VerySource

 Forgot password?
 Register
Search
View: 691|Reply: 5

Database connection issues?

[Copy link]

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-11 10:20:01
| Show all posts |Read mode
Please see the original code:
BOOL CMyApp :: InitInstance ()
{
   ...
AfxOleInit ();
pConn.CreateInstance (__ uuidof (Connection));
try
{
pConn-> Open ("Provider = Microsoft.Jet.OLEDB.4.0; Data Source = ki.mdb", "", "", adModeUnknown);
}
catch (_com_error e)
{
AfxMessageBox ("Database connection failed, confirm whether the database POP.mdb is in the current path!");
return false;
}
return FALSE;
}
extern CMyApp theApp;
void Show ()
{
        CString str;
str = "select * from Name";
        _RecordsetPtr m_pRs;
Ranch
    try
{
m_pRs = theApp.pConn-> Execute ((_ bstr_t) str, NULL, adCmdText);
}
catch (_com_error e)
{
AfxMessageBox (e.ErrorMessage ());
}
catch (...)
{
AfxMessageBox ("Error opening dataset 1!");
         }
Ranch
}
After running: "Invalid pointer" error displayed
Reply

Use magic Report

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-14 20:18:02
| Show all posts
According to my analysis, theApp.pConn was not found, but pConn has been defined.
Reply

Use magic Report

2

Threads

4

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-16 08:54:02
| Show all posts
I have understood that the code is misplaced. AfxOleInit (); and the following code should be placed on CMyDlg dlg;
Reply

Use magic Report

0

Threads

32

Posts

27.00

Credits

Newbie

Rank: 1

Credits
27.00

 China

Post time: 2020-1-16 18:27:01
| Show all posts
It is still placed in the initialization of dloag, that is, in BOOL CYourDlg :: OnInitDialog ()
Reply

Use magic Report

0

Threads

55

Posts

32.00

Credits

Newbie

Rank: 1

Credits
32.00

 China

Post time: 2020-1-28 18:45:01
| Show all posts
It doesn't fit inside BOOL CMyApp :: InitInstance ().
Reply

Use magic Report

0

Threads

13

Posts

7.00

Credits

Newbie

Rank: 1

Credits
7.00

 China

Post time: 2020-7-8 02:15:01
| Show all posts
Use Coinintialize();
Your pConn is not created successfully
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list