Forum Stats

  • 3,827,605 Users
  • 2,260,798 Discussions
  • 7,897,313 Comments

Discussions

Create database programatically c#

Hello all.

I am doing a c# program that can use different data sources, I need to create the database programmatically and then, also programatically, create the tables, stored procedures and functions.

I already did all this with a sql server.

Could you help me to do it with a remote oracle server?

When I create the database directly in oracle the conection run ok.

Server: ORASERVER

Port: 1521

Database: MYDB

User: system

Passwork: pass

this.txt_CnStr.Text = "Data Source=(DESCRIPTION =(ADDRESS = (PROTOCOL = TCP)(HOST = " + this.txt_SD_Servidor.Text + ")(PORT = " +

          this.txt_SD_Puerto.Text + "))(CONNECT_DATA = (SERVER = DEDICATED)(SERVICE_NAME = " + this.txt_SD_BD.Text + ")));User ID=" + this.txt_SD_UserId.Text + ";Password=" + this.txt_SD_Pwd.Text;

dpf = DbProviderFactories.GetFactory("System.Data.OracleClient");

conexion = dpf.CreateConnection();

conexion.ConnectionString = this.txt_CnStr.Text;

conecxion.open();

This run fine.

To create the database I found the following code, but it is for a local server where the program is on the same server as the database: (txt_oradata is the Oracle data path)

using (conexion)

{

     conexion.Open();

     dbcmd = conexion.CreateCommand();

     dbcmd.CommandText = "CREATE TABLESPACE \"" + this.txtDatabase.Text + "\" DATAFILE '" + this.txt_oradata.Text + this.txtDatabase.Text + ".DBF' SIZE 10M AUTOEXTEND ON NEXT 1M";

     dbcmd.ExecuteNonQuery();

}

Thanks in advance