Edit the control file in Oracle 10g Release 2 - sql

I tried to clone an oracle database server to another oracle database server.
After I completed the cloning, when I tried connecting to the database by starting SQL Plus
I got the following errors:
ORA-01157: cannot identify/lock data file 1 - see DBWR trace file
ORA-01110: data file 1: '/home/oracle/oradata/ccisv2/system01.dbf'
I found that while cloning the control file of the original database location also got cloned.
Now in the new server I have the data files located at a different location. and that is not affected in the control file, which is the reason for the error.
In short I need to change the above path
/home/oracle/oradata/ccisv2/
to a new path
/home2/oracle/oradata/ccisv2/
I am not sure how can I change the control file and edit the path of the data file location.
Changing of the location of datafiles is not possible as I have less space in
/home/oracle/oradata/..
Can some one help me with this one...

You'll need to mount the database (not open it) and re-create the controlfile, renaming the data files in the process (see the CREATE CONTROLFILE command):
STARTUP MOUNT;
CREATE CONTROLFILE REUSE SET DATABASE "ORCL" RESETLOGS
MAXLOGFILES NN
MAXLOGMEMBERS N
MAXDATAFILES 254
MAXINSTANCES 1
MAXLOGHISTORY 1815
LOGFILE
GROUP 1 '/home2/oracle/oradata/ccisv2/REDO01.LOG' SIZE 56M,
GROUP 2 '/home2/oracle/oradata/ccisv2/REDO02.LOG' SIZE 56M,
GROUP 3 '/home2/oracle/oradata/ccisv2/REDO03.LOG' SIZE 56M
DATAFILE
'/home2/oracle/oradata/ccisv2/SYSTEM.DBF',
'/home2/oracle/oradata/ccisv2/USERS.DBF',
'/home2/oracle/oradata/ccisv2/sysaux.DBF',
'/home2/oracle/oradata/ccisv2/TOOLS.DBF',
etc...
CHARACTER SET WE8ISO8859P1;
ALTER DATABASE OPEN RESETLOGS;
QUIT;
All of your database files need to be re-identified in the controlfile with their new location.

Easiest is to just rename the datafiles to the new locations:
startup mount;
alter database rename file '/home/oracle/oradata/ccisv2/system01.dbf' to '/home2/oracle/oradata/ccisv2/system01.dbf';
and do this for all your files.
Normally we would use rman duplicate and use the file_name convert to do this for us.
re-creating the controlfile is also an option, renaming the files is easier.

Related

how to create a file in application server with abap programing

I have a file in my D: drive of my computer and I want to copy this file to an SAP application server so that I am able to see my file with transaction AL11.
I know that I can create a file with AL11 but I want do this in ABAP.
Of course in my search I find this code but I cannot solve my problem with it.
data: unixcom like rlgrap-filename.
data: begin of tabl occurs 500,
line(400),
end of tabl.
dir =
unixcom = 'mkdir mydir'. "command to create dir
"to execute the unix command
call 'SYSTEM' id 'COMMAND' field unixcom
id 'TAB' field tabl[].
To upload the file to the application server, there are three steps to be followed. To open the file use the below statement:
Step1: OPEN DATASET file name FOR INPUT IN TEXT MODE ENCODING DEFAULT.
To write into the application server use.
Step2: TRANSFER name TO file name.
Dont forget to close the file once it is transferred.
Step3: CLOSE DATASET file name.
Plese mark with correct answer, if it helps! :)
If you want to do this using ABAP you could create a small report that uses the function module GUI_UPLOAD to get the file from your local disk into an internal table and then write it to the application server with something like this:
lv_filename = '\\path\to\al11\directory\file.txt'.
OPEN DATASET lv_filename FOR OUTPUT IN TEXT MODE ENCODING UTF-8.
LOOP AT lt_contents INTO lv_line.
TRANSFER lv_line TO lv_filename.
ENDLOOP.
CLOSE DATASET lv_filename.
I used CG3Z transaction and with this transaction I was able to copy a file in the application server directory.

BIDS Import from changing file name [wildcard?]

I'm attempting to create a process to import data. I created the entire process and it works, but I'm having trouble creating the variable to find the file name of the csv i want to import automatically. Each time a new csv is uploaded to me it has a timestamp on it. I want to be able to grab that file no matter what the name is and do work to it.
So for example this week the file name would be
filename_4-14-2014.csv
And next week
filename_4_21_2014.csv
And so on into eternity. . .
Is there a way to create a variable that picks up the full file name even though its changing?
After doing some poking around, I've discovered the following...
You can use a file system task to perform the copy operation I was referring to. You can set the input file and the output file as variables. This way you can always know that the file you use for import is always named the same, and has the right data.
You just need to add the variables and a File System Task to your package.
Ok so to accomplish what I wanted I created a Foreach Loop Container. Using the foreach loop container I had it look for any files ending with .csv in my specified folder by using a wildcard [denoted by asterisk: *.csv] .
Within the Foreach Loop container is as follows.
Step 1: File System Task - rename file.
Step 2: Data Flow Task - Import data to sql
Step 3: File System Task - Copy the file to another folder, append datetime to filename
Step 4: File System Task - Delete source file.
I used variables to get all the file and folder names plus datetimes.

Rename a file at runtime with vb.net

i try to rename a file using vb.net in this way:
my.computer.filesyste.rename(oldname,newname)
But if i use a software to recover files deleted, i find a file named :"_ldname", and if i recovery the file "_ldname" i have, in this way, two files equals.
Can i do this without have a duplicate of my file?
Best regards
Sebastiano
You cannot, this is a windows filesystem limitation and nothing to do with programming. Two files cannot have the same name in the same location.
The recovery software should be forcing a rename to Myfile(1).txt or something like that to distinguish between the two files.
You could always use:
If File.Exists(path) = False Then
To make sure the file doesn't already exists. Then if it does exist you could add a "(1)" to the file name.

ERROR attaching adventureworks2012_data.mdf file with sql server 2012

I have been trying to add adventure works database to my SQL server 2012..I tried to attach the database using SQL Server Management Studio as follows: I Right Clicked on Databases > Attach and clicked Add... > selected the AdventureWorks2012_Data file. and then I Selected the log file and removed the log file by clicking on the Remove button then clicked OK but I still get an error that the header file is not a valid database header file and the FILESIZE property is incorrect ......please help me
As Martin suggested, it may be that the file you downloaded is incorrect. You should download a new copy from here (I wouldn't get it anywhere else):
Once you do, don't use the UI for this. Make sure you copy the .mdf file to your instance's data folder. Then run this code in a query window:
CREATE DATABASE AdventureWorks2012
ON (name = 'AdventureWorks2012_data',
filename = 'drive:\path\AdventureWorks2012_Data.mdf')
FOR ATTACH_REBUILD_LOG;
You will get this "error" message:
File activation failure. The physical file name "drive:\path\AdventureWorks2012_Log.ldf" may be incorrect.
This is just SQL Server telling you that it didn't find the log file; it should still create one for you unless you have other issues (permission denied, lack of space, the same name file already exists, etc).

Deploy a database project build output (dbschema & co) to various databases

I am trying to build a database project, and then use the output along with VSDBCMD to deploy it to different databases. I have added different sqldeployment & sqlcmdvars files corresponding to the environments I aim, but I am not able to change the following variables, which seem to be readonly (DatabaseName, DefaultDataPath, DefaultLogPath). For example I would like to have QA and UA databases on the same server instance so I need my deployment script to work with different database names and files path. Moreover when I build my database project in TFS I cannot seem to find the specific sqlcmdvars & sqldeployment files (ex MyDatabase-QA.sqlcmdvars, MyDatabase-UA.sqlcmdvars) in my drop folder.
Am I doing something wrong? What other options do I have?
Thanks in advance!
A little late for you maybe, but after a bit of digging, if you want to set, for a example a custom file path for your MDF/LDF, I did the following.
Create a new var in the sqlcmdvars file.
use this var in the File sql file at as follows: DBProject\Schema Objects\Database Level Objects\Storage\Files
ALTER DATABASE [$(DatabaseName)]
ADD FILE (NAME = [MYDBNAME], FILENAME = '$(DataLocation)\MyDatabaseName.mdf', SIZE = 2304 KB, FILEGROWTH = 1024 KB) TO FILEGROUP [PRIMARY];