Re: Conditionally create database with .NET
Posted in 2008
On Mon, Nov 24, 2008 at 5:43 AM, Obnoxio The Clown <obnoxio@serendipita.com> wrote: > Sheshnarayan Agrawal wrote: >> >> For this you have to open another connection (object) with connection >> string whereas you don't provide value of "database=" attribute. This >> will connect to only server and not database. Hence later on in your >> command object you can execute "create database ..." query. >> >> For example, In you existing scenario you might be saying something like >> this >> >> conn = new IfxConnection("Server=ol_shesh_ids1150;User >> ID=informix;password=xxx;Database=sysmaster;"); >> >> In your new connection string you have to say (without "database=" >> attribute) >> >> conn_new = new IfxConnection("Server=ol_shesh_ids1150;User >> ID=informix;password=xxx;"); >> >> and then create command object and run "create database .." query. > > Is that a .NET thing? Because I can't think of any other way of > connecting that would demand this. Not really. If you use ESQL/C and do: CONNECT TO "somedatabase@someserver"; then you end up with a connection on which you cannot use any of the DATABASE statements. If you want to do database management, as opposed management of one database, then you need to do: CONNECT TO "@someserver"; Now you can do CREATE DATABASE, DROP DATABASE, DATABASE and so on to your heart's content. The .NET syntax doesn't include the '@', but it does drop the databasename, so I assume the .NET driver actually, behind the scenes, does the equivalent of the '@servername' stuff. You can also do: CONNECT TO DEFAULT; This is effectively the same thing - somewhat cleaner, though. -- Jonathan Leffler #include <disclaimer.h> Email: jleffler@earthlink.net, jleffler@us.ibm.com Guardian of DBD::Informix v2008.0513 -- http://dbi.perl.org/ "Blessed are we who can laugh at ourselves, for we shall never cease to be amused." NB: Please do not use this email for correspondence. I don't necessarily read it every week, even.