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数据库 ...
随机推荐
- Python: Neural Networks
这是用Python实现的Neural Networks, 基于Python 2.7.9, numpy, matplotlib. 代码来源于斯坦福大学的课程: http://cs231n.github. ...
- CodeForces - 1000E :We Need More Bosses(无向图缩点+树的直径)
Your friend is developing a computer game. He has already decided how the game world should look lik ...
- final修饰变量
final修饰基本类型变量 当使用final修饰基本类型变量时,不能对基本类型变量重新赋值,因此基本类型变量不能被改变 final修饰引用类型变量 当使用final修饰引用类型变量时,它保存的仅仅是一 ...
- hive通过spark导入hbase
发现采用shcjar的话,总是执行到某个点就停止了 于是我打算尝试一下直接说哦用org.apache.hadoop.hbase.spark这个datasource看看 确实不行,即使没有createt ...
- 选中DataGrid的Cell而不是row
主要是针对DataGridCellsPresenter而不是SelectiveScrollingGrid,使用时DataGridRow应用这个style就可以了. <Style x:Key=&q ...
- POCO库中文编程参考指南(9)Poco::Net::DNS
1 Poco::Net::DNS namespace Poco { namespace Net { class Net_API DNS { public: static HostEntry hostB ...
- 杂项随记:gcc/objdump/section等
gcc -g 如果不打开-g或者-ggdb(GDB专用)调试开关,GCC编译时不会加入调试信息,因为这会增大生成代码的体积.GCC采用了分级调试,通过在-g选项后附加数字1.2或3来指定在代码中加入调 ...
- 最短路径 一 Dijkstra 模板(O(n^2))
题目传送:http://hihocoder.com/problemset/problem/1081 #include<iostream> #include<cstdio> #i ...
- win7 x64 eclipse_kepler下编译 hadoop1.1.2-celipse-plugin
1.编译前准备 a) 下载和解压hadoop-1.1.2.tar.gz b) 下载并配置ant 2.配置 a) 进入hadoop-1.1.2\src\contrib ...
- # program once 用途 及与 ifndef使用异同
在头文件中用这种写法就是为了该头文件被重复包含时不会出现符合重定义的错误. 效果等同于 #ifndef __xxx__ #define __xxx__ ... #endi ...