Re: Using DBLIB With Azure

"James K. Lowden" <[email protected]>
Newsgroups gmane.comp.db.tds.freetds
Message-ID <[email protected]>
On Wed, 9 Mar 2011 13:26:53 -0500
Ken Collins <[email protected]> wrote:

> Azure does not have a notion of "USE ..." or has a way to specify a default database with the user account

https://github.com/rails-sqlserver/tiny_tds

OK, I think I finally get the picture.  

If I understand aright, the TinyTds user -- an elf or gnome, perhaps? -- should be able to say something like this:

client = TinyTds::Client.new(:username => 'sa', :password => 'secret', :dataserver => 'mytds_box', :database = 'mydb')

and you want to know how to deal with 'mydb'.  

Simple: dbuse().  

You're not obliged to use only one db-lib function when the connection is established.  Just call dblogin(), dbopen(), and dbuse(), in that order.  Job done.  

If you really, really, really want to, you could extend db-lib.  It's a mini project: 

1.  add dbname to TDSLOGIN
2.  add case to set dbname in dbsetlname
3.  add macro DBSETLDBNAME
4.  refer to TDSLOGIN::dbname when the structure is copied to TDSCONNECTION.  

An alternative would be to add a new function, dbopendb(), that would take three parameters instead of two.  

Could be done, minorly useful.  To a db-lib program, it's hard to see much advantage to 

	DBSETLDB("mydb")
over
	dbuse("mydb")

especially because dbuse() can fail, keeping the connection viable.  

If you put the dbname in the login packet, you invite the ODBC problem -- I say problem, but others might say feature -- of disallowing the connection because the database name is wrong/unavailable.  It's one of my (least) favorite error messages: you can't login because the username/password is invalid OR because you're not granted access to the database.  Such, such are the joys of troubleshooting.  Nothing like ambiguity with your coffee.  

But I'm sure the TinyTds user won't suffer the same.  ;-)

HTH (this time). 

--jkl
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.