简体   繁体   中英

How to execute an .SQL script file using c# for Oracle DB

I need to execute.SQL scripts stored in local folder into Oracle DB using C#. and so far searching for it I came across solution which are for SQL server so is there a way to execute it for Oracle DB.

You can try the following to execute from Oracle:

using Oracle.ManagedDataAccess.Client;
using Oracle.ManagedDataAccess.Types;

string oraclesqlConnectionString = "Data Source=(local);Initial Catalog=AdventureWorks;Integrated Security=True";

FileInfo file = new FileInfo("C:\\myscript.sql");

string script = file.OpenText().ReadToEnd();

OracleConnection conn = new OracleConnection(oraclesqlConnectionString);

Server server = new Server(new ServerConnection(conn));

server.ConnectionContext.ExecuteNonQuery(script);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM