如何在ADO.NET中以编程方式创建oracle数据库,并使用userId + password创建一个架构,这样我就可以转到我不喜欢的工具sql oracle开发人员工具,我只是创建一个连接进入:
答案 0 :(得分:6)
我以前用SQL做过但从未尝试使用过ADO.NET ......
string connectionString = "...";
string oracleDataPath = "C:\\PATH_TO_ORADATA\\";
string username = "NEW_USER";
string password = "NEW_PWD";
string schema = "NEW_SCHEMA";
using (OracleConnection conn = new OracleConnection(connectionString))
{
conn.Open();
OracleCommand cmd = conn.CreateCommand();
cmd.CommandText = "CREATE TABLESPACE \"" + schema + "\" DATAFILE '" + oracleDataPath + schema + ".DBF' SIZE 10M AUTOEXTEND ON NEXT 1M";
cmd.ExecuteNonQuery();
cmd.CommandText = "CREATE USER \"" + username + "\" IDENTIFIED BY \"" + password + "\" DEFAULT TABLESPACE \"" + schema + "\" TEMPORARY TABLESPACE TEMP";
cmd.ExecuteNonQuery();
cmd.CommandText = "GRANT CONNECT TO \"" + username + "\"";
cmd.ExecuteNonQuery();
cmd.CommandText = "ALTER USER \"" + username + "\" QUOTA UNLIMITED ON \"" + schema + "\"";
cmd.ExecuteNonQuery();
}
在连接字符串上使用ADMIN / DBA帐户 将oracleDataPath设置为Oracle保存其数据文件的路径。
让我知道它是否有效: - )