C#来做oracle还原,调用oracle自带函数imp.exe时,需要注意的是:
1、imp.exe 中fromuser 和touser两个关键字; fromuser与exp.exe中的owner对应,为表的所有者,都可以是多个参数,如:fromuser=(A,B,C)
2、imp.exe 进行恢复数据库时,要确定一下恢复用户(方案)的表空间,一般默认为users空间
3、在获取到表空间权限后,要对用户进行恢复权限设置,主要是对表空间的限制,一般处理:grant unlimited tablespace to user(自己的用户)
4、程序中设置了oracle服务端的exp和imp的路径
注意:在C#做备份和还原的时候,都是调用的oracle服务器的自带函数
   在用进程来调用备份和还原时,备份完成和结束后,要进行进程释放。 //开始恢复数据库
private void button1_Click(object sender, EventArgs e)
{ string tables = ""; //创建要还原的方案
//从备份的方案中读取
FileStream fs=new FileStream (textBox6.Text,FileMode.Open);
StreamReader smread=new StreamReader(fs);
smread.BaseStream.Seek(,SeekOrigin.Begin);
string strLine = "";
string backusers = "";
while ((strLine=smread.ReadLine()) != null)
{
backusers += strLine + ",";
} if (backusers.Length > )
{
backusers = backusers.Substring(, backusers.Length - );
tables = backusers;
}
String[]userArr=backusers.Split(',');
string sqluser="";
String[] marks;
string newtables = "";
using (OracleConnection oracon = orclConnection())
{
try
{
oracon.Open();
}
catch (Exception ex)
{
MessageBox.Show("链接数据库错误,错误原因:"+ex.Message.ToString());
}
using (OracleTransaction tran = oracon.BeginTransaction())
{
using (OracleCommand com = new OracleCommand())
{
com.Transaction = tran; string newuser = "";
com.Connection = oracon;
//com.Connection.Open(); foreach (string s in userArr)
{
newuser = s; //判断是否按照默认的标识进行还原
if (!checkBox1.Checked)//不默认
{
newuser = "";
//tables = "";
//修改还原的方案名称后缀(标识)
marks = s.Split('_');
//修改标识
marks[marks.Count() - ] = textBox2.Text.ToUpper();
foreach (string mark in marks)
{
newuser += mark + "_";
}
newuser = newuser.Substring(, newuser.Length - );
newtables += newuser + ",";
} com.CommandText = "Select count(*) from all_users where username='" + newuser + "'";
int i = Convert.ToInt32(com.ExecuteScalar()); //如果存在,删除后还原
if (i > )
{
sqluser = "drop user "+newuser+" cascade"; com.CommandText = sqluser;
try
{
com.ExecuteNonQuery();
com.CommandText = "create user " + newuser + " identified by " + newuser + " default tablespace users";
com.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
tran.Rollback();
}
} if (i == )
{
sqluser = "create user " + newuser + " identified by " + newuser+" default tablespace users";
com.CommandText = sqluser;
try
{
com.ExecuteNonQuery();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
tran.Rollback();
}
} sqluser = "grant connect,resource,dba to " + newuser;
com.CommandText = sqluser;
com.ExecuteNonQuery(); sqluser = "alter user system quota unlimited on users" ;
com.CommandText = sqluser;
com.ExecuteNonQuery(); //指定还原的方案为还原默认的表空间
sqluser = "grant unlimited tablespace to "+newuser ;
com.CommandText = sqluser;
com.ExecuteNonQuery();
} if (!checkBox1.Checked)
{
tables = newtables.Substring(, newtables.Length - );
}
tran.Commit();
}
}
} //} string filename = textBox5.Text;//恢复文件路径
//导入程序路径
Process p = new Process();
//p.StartInfo.FileName= "D:\\app\\oracle\\product\\11.2.0\\dbhome_1\\BIN\\imp.exe";
p.StartInfo.FileName = System.Configuration.ConfigurationSettings.AppSettings["pathrestroe"].ToString();
p.StartInfo.UseShellExecute = true;
p.StartInfo.CreateNoWindow = false;
p.StartInfo.Arguments = "system/system@orcl file=" + filename + " fromuser=("+backusers+") touser=(" +tables+ ") ignore=y" ;
//p.StartInfo.Arguments = "system/system@orcl file=" + filename + " fromuser=HYGISTK_CONTROLLINE_ZL2 touser=HYGISTK_CONTROLLINE_ZL ignore=y";
p.Start();
p.WaitForExit();
p.Dispose();
}

C#oracle还原imp实例的更多相关文章

  1. 深入理解Oracle的imp/exp 和各版本之间的规则

    Oracle数据中IMP/EXP工具可用于对数据进行迁移.IMP命令用于把Dmp文件从本地导入到远程数据库服务器,而EXP命令则是把数据从远程数据库服务器导出到本地的Dmp文件.其功能相当于Oracl ...

  2. Oracle DataBase单实例使用ASM案例(1)--ASM基本概念

    版权声明:本文为博主原创文章,未经博主允许不得转载. Oracle DataBase单实例使用ASM案例(1)--ASM基本概念 系统环境: 操作系统:RH EL5-64 Oracle 软件: Ora ...

  3. Linux平台oracle 11g单实例 + ASM存储 安装部署 快速参考

    操作环境:Citrix虚拟化环境中申请一个Linux6.4主机(模板)目标:创建单机11g + ASM存储 数据库 1. 主机准备 2. 创建ORACLE 用户和组成员 3. 创建以下目录并赋予对应权 ...

  4. oracle中imp命令详解 .

    转自http://www.cnblogs.com/songdavid/articles/2435439.html oracle中imp命令详解 Oracle的导入实用程序(Import utility ...

  5. 【转】Oracle - 数据库的实例、表空间、用户、表之间关系

    [转]Oracle - 数据库的实例.表空间.用户.表之间关系 完整的Oracle数据库通常由两部分组成:Oracle数据库和数据库实例. 1) 数据库是一系列物理文件的集合(数据文件,控制文件,联机 ...

  6. oracle中imp命令具体解释

    oracle中imp命令具体解释 Oracle的导入有用程序(Import utility)同意从数据库提取数据,而且将数据写入操作系统文件.imp使用的基本格式:imp[username[/pass ...

  7. oracle exp imp

    oracle exp/imp

  8. oracle在imp订单具体解释

    oracle在imp订单具体解释 Oracle导入实用程序(Import utility)同意从数据库中提取数据,和写入数据到一个操作系统文件项目.imp所用的基本格式:imp[username[/p ...

  9. oracle数据库与实例

    ========================================================================================== oracle数据库 ...

随机推荐

  1. ACM学习历程—HDU1717 小数化分数2(gcd)

    Description Ray 在数学课上听老师说,任何小数都能表示成分数的形式,他开始了化了起来,很快他就完成了,但他又想到一个问题,如何把一个循环小数化成分数呢? 请你写一个程序不但可以将普通小数 ...

  2. Mysql 5.7.18忘记密码

    5.7.18密码修改发生了变化,旧版的方法不再奏效. 1. ps -ef | grep mysqld,kill掉启动的mysql服务: 2. 创建/etc/my.cnf,添加: [mysqld] sk ...

  3. vmware ubuntu14.04 忘记密码

    重置root密码 启动系统,一直点击esc键盘,出现如下界面,选择Advanced options for Ubuntu 按回车键确认: 选择recovery mode,按 e : 到 linux / ...

  4. 使用XMLConfiguration解析xml,PropertiesConfiguration解析properties等相应信息

    org.apache.commons.configuration.XMLConfiguration; Apache Common-Configuration工具可以从Properties文件,XML文 ...

  5. java 获取路径与各文件目录的…

    java 获取路径 博客分类: MyJava JavaJSPWebTomcat编程  转至:http://geeksun.iteye.com/blog/356339 (1).request.getRe ...

  6. Will you still need me?

    ON FRIDAY, the National Bureau of Statistics announced that China's working-age population shrank la ...

  7. hduoj题目分类

    基础题:1000.1001.1004.1005.1008.1012.1013.1014.1017.1019.1021.1028.1029.1032.1037.1040.1048.1056.1058.1 ...

  8. PHP json 对象 数组互相转换

    json格式转为数组/对象 json_decode() json 对象/数组转json格式 json_encode()

  9. SLAM的现在与未来

    http://geek.csdn.net/news/detail/202128 作者:高翔,张涛,刘毅,颜沁睿. 编者按:本文节选自图书<视觉SLAM十四讲:从理论到实践>,系统介绍了视觉 ...

  10. 51nod1101(dp)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1101 题意:中文题诶- 思路:dp 我们用dp[i][j]存 ...