我有一个oracle数据库,每当用户帐户被锁定时,我都会运行命令
ALTER USER xxxxx ACCOUNT UNLOCK;
有没有办法从C#应用程序执行此操作?
答案 0 :(得分:2)
与其他数据库相同。您将在打开的数据库连接上创建IDbCommand
,为其分配要触发的查询并执行它。
static void Main()
{
string constr = //Connection string
DbProviderFactory factory = DbProviderFactories.GetFactory("Oracle.DataAccess.Client");
try
{
using(DbConnection conn = factory.CreateConnection())
{
conn.ConnectionString = constr;
conn.Open();
using(DbCommand cmd = conn.CreateCommand())
{
cmd.CommandText = "ALTER USER xxxxx ACCOUNT UNLOCK;";
cmd.ExecuteNonQuery();
}
}
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
Console.WriteLine(ex.StackTrace);
}
}