C#oracle还原imp实例
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实例的更多相关文章
- 深入理解Oracle的imp/exp 和各版本之间的规则
Oracle数据中IMP/EXP工具可用于对数据进行迁移.IMP命令用于把Dmp文件从本地导入到远程数据库服务器,而EXP命令则是把数据从远程数据库服务器导出到本地的Dmp文件.其功能相当于Oracl ...
- Oracle DataBase单实例使用ASM案例(1)--ASM基本概念
版权声明:本文为博主原创文章,未经博主允许不得转载. Oracle DataBase单实例使用ASM案例(1)--ASM基本概念 系统环境: 操作系统:RH EL5-64 Oracle 软件: Ora ...
- Linux平台oracle 11g单实例 + ASM存储 安装部署 快速参考
操作环境:Citrix虚拟化环境中申请一个Linux6.4主机(模板)目标:创建单机11g + ASM存储 数据库 1. 主机准备 2. 创建ORACLE 用户和组成员 3. 创建以下目录并赋予对应权 ...
- oracle中imp命令详解 .
转自http://www.cnblogs.com/songdavid/articles/2435439.html oracle中imp命令详解 Oracle的导入实用程序(Import utility ...
- 【转】Oracle - 数据库的实例、表空间、用户、表之间关系
[转]Oracle - 数据库的实例.表空间.用户.表之间关系 完整的Oracle数据库通常由两部分组成:Oracle数据库和数据库实例. 1) 数据库是一系列物理文件的集合(数据文件,控制文件,联机 ...
- oracle中imp命令具体解释
oracle中imp命令具体解释 Oracle的导入有用程序(Import utility)同意从数据库提取数据,而且将数据写入操作系统文件.imp使用的基本格式:imp[username[/pass ...
- oracle exp imp
oracle exp/imp
- oracle在imp订单具体解释
oracle在imp订单具体解释 Oracle导入实用程序(Import utility)同意从数据库中提取数据,和写入数据到一个操作系统文件项目.imp所用的基本格式:imp[username[/p ...
- oracle数据库与实例
========================================================================================== oracle数据库 ...
随机推荐
- 洛谷 P2962 [USACO09NOV]灯Lights
题目描述 Bessie and the cows were playing games in the barn, but the power was reset and the lights were ...
- fabnacii数列
Fibonacci数 时间限制:3000 ms | 内存限制:65535 KB 难度:1 描述 无穷数列1,1,2,3,5,8,13,21,34,55...称为Fibonacci数列,它可以递归地定义 ...
- CentOS下安装配置Samba服务器
0 环境介绍 VMWARE12下安装的CENTOS7虚拟机.宿主机为WIN7. 1 离线安装 费了九牛二虎之力,下载各种依赖,还是有问题,转向在线安装. 2 在线安装 虚拟机采用默认的配置: 其次,网 ...
- nodejs写文件
var fs = require('fs'); 2 var txt = "以上程序使用fs.readFileSync从源路径读取文件内容,并使用fs.writeFileSync将文件内容写入 ...
- Auto Layout Guide----(一)-----Understanding Auto Layout
Understanding Auto Layout 理解自动布局 Auto Layout dynamically calculates the size and position of all the ...
- 1.4 DVWA亲测文件上传漏洞
Low 先看看源代码: <?php if(isset( $_POST[ 'Upload' ] ) ) { // Where are we going to be writing to? $tar ...
- HDU - 1176 免费馅饼 DP多种状态转移
免费馅饼 都说天上不会掉馅饼,但有一天gameboy正走在回家的小径上,忽然天上掉下大把大把的馅饼.说来gameboy的人品实在是太好了,这馅饼别处都不掉,就掉落在他身旁的10米范围内.馅饼如果掉在了 ...
- .net实现IHttpModule接口顾虑器
这篇文章主要介绍了C#使用IHttpModule接口修改http输出的方法,涉及C#操作IHttpModule接口的相关技巧,非常具有实用价值,需要的朋友可以参考下 本文实例讲述了C#使用IHtt ...
- div内textarea 居中
textarea 实现div内居中,可以使用text-align:center,因其为行内元素.
- ue4 改c++类名
http://blog.csdn.net/chinahaerbin/article/details/50855135