Click here to Skip to main content
15,885,757 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,
i connect to myDatabase (sql server).

CDatabase m_database;
bool p=m_database.Open(_T("myDatabase "),0,0,_T("ODBC;UID=user1"),1);


myDatabase created in Sql Server 2008 :
server type: Database Enginge<br />
server name: my-pc\SQLEXPRESS<br />
authentication: Windiws Authentication <br />
user name: my-pc\user1


CRecordset m_recordset(&m_database);
m_recordset.Open (CRecordset :: snapshot, _T("select * from myTable"), CRecordset::readOnly);


error:
Invalid object Name 'myTable'. Statement(s) could not be prepared


how do i resolve this problem?
Posted
Comments
CHill60 27-Mar-14 15:59pm    
Check the value of p ... is it True? If not then your .Open command is wrong.
If p is True then do you have a table on your database called "myTable"?
Zon-cpp 27-Mar-14 16:08pm    
hello,
yes, p is true and myTable is created.
CHill60 27-Mar-14 16:10pm    
Are those spaces in CRecordset :: snaphot really there in your code - doesn't look right to me
Zon-cpp 27-Mar-14 16:13pm    
without those spaces, too, i have "Statement ..." error.
CHill60 27-Mar-14 16:16pm    
Can you try m_recordset.Open (CRecordset::readOnly, _T("select * from myTable")); - don't worry ::snapshot is the default anyway

1 solution

services of sql server should be running. (sql server explorer and sql server browser. manage them in sql server configuration manager.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900