c# - .NET / Oracle: How to execute a script with DDL statements programmatically -
i want programmatical schema manipulation against oracle database in c#. therefore, struggle basic issues.
the ddl sql statements located in script file. not want use sqlplus.exe, want use oraclecommand out of odp.net assemblies (system.oracle.dataaccess). here's example of script file:
script.sql:
drop table abcdef; drop table ghijkl;
i want point out:
- the script contains ddl statements (data definition language)
- the script contains empty lines
- the script contains more 1 statement
the following code should execute script:
var content = file.readalltext("script.sql"); using (var oracleconnection = new oracleconnection(_connectionstring)) { oracleconnection.open(); using (var command = new oraclecommand(content) { connection = oracleconnection }) { command.commandtype = commandtype.text; command.executenonquery(); } }
executing code, oracle error:
oracle.dataaccess.client.oracleexception: ora-00911: invalid character
maybe there issue formatting of statements, think. hint appreciated. thank you.
---edit---
to summarize needs in simple way: search approach execute sql/ddl script, executable sql plus, programmatically c#.
as @steve said, semicolons causing error. , can't wrap entire file single execute immediate
command, since can execute 1 statement @ time. need parse file , execute each command on own, removing semicolon delinates commands. parsing have deal string literals, noted, in addition containing semicolons may contain doubled single quotes ('') within single quotes (') begin , end string literal.
Comments
Post a Comment