Conditionally create database with .NET
Posted in 2008
Topics: General Discussion
Hello, Using the .NET provider for Informix, I need to conditionally create a database. So far, I connect to the 'sysmaster' database, to perform a 'SELECT name FROM sysdatabases WHERE name='databasename' query, which tells me if the desired database already exists. But then, if the database doesn't exist, I want to create it. So I try a 'CREATE DATABASE' command, which fails, because an explicit connection has been made. Then I tried a 'DISCONNECT ALL' first, but now IDS says it's a syntax error. Can anybody tell me what's wrong here?
Peter Laman wrote: > Hello, > > Using the .NET provider for Informix, I need to conditionally create a > database. So far, I connect to the 'sysmaster' database, to perform a > 'SELECT name FROM sysdatabases WHERE name='databasename' query, which > tells me if the desired database already exists. But then, if the > database doesn't exist, I want to create it. So I try a 'CREATE > DATABASE' command, which fails, because an explicit connection has > been made. Sounds a bit odd to me. > Then I tried a 'DISCONNECT ALL' first, but now IDS says > it's a syntax error. > > Can anybody tell me what's wrong here? CLOSE DATABASE? -- Cheers, Obnoxio The Clown http://obotheclown.blogspot.com
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. HTH.. -Shesh Peter Laman <peter.laman@gmail.com> Sent by: informix-list-bounces@iiug.org 24/11/2008 18:25 To informix-list@iiug.org cc Subject Conditionally create database with .NET Hello, Using the .NET provider for Informix, I need to conditionally create a database. So far, I connect to the 'sysmaster' database, to perform a 'SELECT name FROM sysdatabases WHERE name='databasename' query, which tells me if the desired database already exists. But then, if the database doesn't exist, I want to create it. So I try a 'CREATE DATABASE' command, which fails, because an explicit connection has been made. Then I tried a 'DISCONNECT ALL' first, but now IDS says it's a syntax error. Can anybody tell me what's wrong here? _______________________________________________ Informix-list mailing list Informix-list@iiug.org http://www.iiug.org/mailman/listinfo/informix-list
Thanks Sheshnarayan Agrawal, your solution works. Thanks all the others for your replies. Peter