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. CodeForces-329C(div1):Graph Reconstruction(随机&构造)

    I have an undirected graph consisting of n nodes, numbered 1 through n. Each node has at most two in ...

  2. manacher(无讲解)

    BZOJ3325: [Scoi2013]密码 https://lydsy.com/JudgeOnline/problem.php?id=3325 分析: 根据前i个字符和一些不等和相等条件就可以确定每 ...

  3. 图形化升级单机oracle 11.2.0.1 到 11.2.0.4

    1. 讲补丁包上传到 oracle server ,解压.安装 [root@11g ~]#unzip p13390677_112040_Linux-x86-64_1of7.zip -d /tmp &a ...

  4. 《TCP/IP详解卷一:协议》 概述

    分层           TCP/IP协议族是一组不同层次上的多个协议的组合.TCP/IP通常被认为是一个四层次协议系统.   链路层(数据链路层或网络接口层):通常包括操作系统中的设备驱动程序和计算 ...

  5. Docker入门(七):部署app

    这个<Docker入门系列>文档,是根据Docker官网(https://docs.docker.com)的帮助文档大致翻译而成.主要是作为个人学习记录.有错误的地方,Robin欢迎大家指 ...

  6. html中连续点击某个标签会出现蓝色的解决方法

    给标签加上下面的属性就可以了,也可以把这些属性建立一个class名,谁需要的时候加上也ok -moz-user-select: none; /*mozilar*/ -webkit-user-selec ...

  7. 在Spring环境下存取properties文件…

    Spring中PropertyPlaceholderConfigurer的使用 (1) 基本的使用方法是 classpath:/spring/include/dbQuery.properties 其中 ...

  8. 使用 Addr2line 将函数地址解析为函数名

    用 Addr2line 将函数地址解析为函数名 原文链接:http://www.ibm.com/developerworks/cn/linux/l-graphvis/ Addr2line 工具(它是标 ...

  9. Python:通过一个小案例深入理解IO多路复用

    通过一个小案例深入理解IO多路复用 假如我们现在有这样一个普通的需求,写一个简单的爬虫来爬取校花网的主页 import requests import time start = time.time() ...

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

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