Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

problem with SQLStringConnect

Status
Not open for further replies.

nevin2007

Programmer
Aug 21, 2009
31
IR
Hi
I have a problem with find database name when using SQLStringConnect function.
perviusly i used

Code:
hlconn=SQLConnect(connname)
dbname=SQLGetprop(hlconn,'Database')

But now i must use SQLStringConnect function. all things is ok and SQLExec works but

Code:
dbname=SQLGetprop(hlconn,'Database')

return empty value.
Why?
How can i find database name?
thanks
 
Database" is not a property you can get via SQLGetProp, only from CursorGetProp. SQLGetProp properties with D are DataSource, DisconnectRollback, DispLogin and DispWarning, but not Database.
And in CursorGetProp you only get a DBC in the database property, not a SQL Server or other db name.

What is your remote database? In SQL Server you either specify the database in the connection string or you SQLExec(h,"USE databasename;") to switch to some database. You can always access all databases of a server instance you're connected to by the full qualilfied name db.schema.table, eg the typical schema is dbo, so something like YourDB.dbo.SomeTable works, even when another db is used.

In MS SQL Server you may execute SQLEXEC(h,"Select DB_Name()")

Bye, Olaf.




 
What exactly are you trying to find? is it the name of the actual database, in the sense of a collection of tables, views, etc? Or is the name of the back-end server (e.g. "SQL Server", "MySQL", etc.)?

The point is that any given back-end can host multiple databases. In most cases, one of the databases will be the current or default database (a bit like the current work area in FoxPro). Is that what you are looking for?

If so, Olaf has given you a possible answer: [tt]SQLEXEC(h,"Select DB_Name()[/tt]". But be aware that that is specific to Micrososft SQL Server. In MySQL, the syntax would be [tt]SQLEXEC(h,"Select Database()[/tt]. Other back-ends will have different methods or syntax.

If you could clarify what you are looking for, and which back-end you are using, we might be able to help.

Mike



__________________________________
Mike Lewis (Edinburgh, Scotland)

Visual FoxPro articles, tips and downloads
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top