Hi
I can connect successfully to the Microsoft SQL Server "Beauty" (get also nonzero for successfull connection). If i run the application (see code below). I get following Error Message "Illegal Objectname 'TestTabelle' ". I double checked the SQL statement and it should be correct. Even the spelling of TestTabelle is right. For testing purposes I've also included 5-6 data records in the tabel.
I try to connect via ODBC. I've created the database with MS SQL Enterprise Manager. Right Click -> Create New Database. I called it "Test" and created in "Test" a new Table, which is called "TestTabelle".
I found information how i can connect to a ms sql server "Beauty", i've also found how i can connect to a table, BUT where is the information which Database ?`in my case it should be Test.
how can i setup a default database... Cause in my application i can't access my Test Database.... See code below :(
Why is this code BOLD not working if i try to select a database ?
Thank You
Indian
{
CDBVariant value;
char sql_statement [2048] = "";
//CDatabase object "db" created to connect database
CDatabase db;
db.OpenEx(_T("DSN=Beauty;UID=Administrator"), CDatabase::noOdbcDialog);
//CRecordset object "rs" created to access and manipulate database records.
CRecordset rs(&db);
strcpy(sql_statement,_T("SELECT * FROM TestTabelle")); <- NOT WORKING... GETTING ERROR MESSAGE if i use this sql_statement " USE TEST; SELECT * FROM TestTabelle"
rs.Open(CRecordset::forwardOnly,sql_statement);
//Get quantity from Database
int n = rs.GetODBCFieldCount( );
while(!rs.IsEOF())
{
for( int i = 0; i < n; i++ )
{
rs.GetFieldValue("index",value);
m_Buy_List.InsertItem(i,LPCTSTR(value.m_pstring));
rs.GetFieldValue("product",value);
m_Buy_List.SetItemText(i,2,LPCTSTR(value.m_pstring ));
rs.GetFieldValue("price",value);
m_Buy_List.SetItemText(i,3,LPCTSTR(value.m_pstring ));
}
rs.MoveNext( );
}
//Close records access.
rs.Close( );
//Close database connection.
db.Close();
}double-click on Administrator (login) and select the default database from the drop-down box at the bottom of this dialog box.|||Better yet, use a more explicit query. Try:
strcpy(sql_statement,_T("SELECT * FROM Test.TestTabelle"));|||Better yet, use a more explicit query. Try:
strcpy(sql_statement,_T("SELECT * FROM Test.TestTabelle"));|||Sorry. Just replace the line in your code.
You could also skip ODBC, and specify the database in your connection string by using OLEDB.
Try this line in your code to connect to the server...
//CDatabase object "db" created to connect database
CDatabase db;
db.OpenEx(_T("Provider=SQLOLEDB.1;Data Source=Beauty;Initial Catalog=Test;UID=Administrator"), CDatabase::noOdbcDialog);|||i figured it out
thx
Monday, March 26, 2012
MS SQL Server Database Connection Problems
Labels:
application,
beauty,
code,
connect,
connection,
database,
hii,
microsoft,
mysql,
nonzero,
oracle,
run,
server,
sql,
successfull,
successfully
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment