ERROR attaching adventureworks2012_data.mdf file with sql server 2012 - sql

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).

Related

I am trying to copy a file, but getting error message

I am new to postgres, probably missing something silly like (the correct name of my directory). Can someone guide me?
I am following book instructions, Practical SQL by Anthony DeBarros
Code:
copy us_counties_2010 from 'C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv' with (FORMAT CSV, HEADER);
Error:
ERROR: could not open file
"C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv" for reading:
Permission denied HINT: COPY FROM instructs the PostgreSQL server
process to read a file. You may want a client-side facility such as
psql's \copy. SQL state: 42501
copy us_counties_2010 from
'C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv' with (FORMAT
CSV, HEADER);
Expected:
Query returned successfully: 3143 rows affected
Actual:
ERROR: could not open file
"C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv" for reading:
Permission denied HINT: COPY FROM instructs the PostgreSQL server
process to read a file. You may want a client-side facility such as
psql's \copy. SQL state: 42501
All that is to be done is:
Go to Properties of that particular file by right clicking on it. Then, go to Security tab of the displayed Properties dialog box. Click on Edit option. Permissions dialog box appears, then click on Add button. Type 'Everyone' (without apostrophes) in the "Enter the object names to select" description box and click on OK button. Then, make sure all the checkboxes of "Permissions for Everyone" are selected by just ticking the "Full Control" check box to allow the control access without any restriction. Then, Apply and OK all the tabs to apply all the changes done.
You can now run/execute the query without any errors.
As the message tells you, Postres is not allowed to read the file.
If you want to fix that open the Task Manager, and click on "Show processes from all users". Look for the rows with the image name postgres.exe (likely more than one). Remember the value in the column "User Name" (it's probably NETWORK SERVICE). Open the properties of your file, add that user in the "Security" tab and grant read access to them.
Or use psql's \copy as the message suggests.
copy us_counties_2010 (your column name)//(country_code, latitude, longitude, country, population)
FROM 'D:\us_counties_2010 .csv' DELIMITER ',' csv HEADER
Your csv file should be in other than C drive. It can't access your C drive. Store it in D drive or any other it will work perfect.
Change the Location of data file and path to Drive['D:\us_counties_2010.csv' ] it will work.
The permission is denied because your files[us_counties_2010.csv] is in 'C' Drive ['C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv'] which is a Windows Drive and permissions are restricted and may not be changed easily & impossible without administrative privileges.
Good Luck & happy programming!
If you are using PSQL, run it as administrator, then you shouldn't have any problem when you are using COPY
In the case when creating a table as well as importing data from a CSV file, we can skip the query and use the program itself. To do this, simply right-click on your table in the tree on the left and select the Import/Export… menu item.
A window will appear with the slider set to Import. Then select the source file and set the format to CSV. Set the Header to Yes if your file has a header. The only thing left is to select the delimiter (usually a comma).
When you click OK, the data will be imported.
For a better understanding, you can refer original article.
https://learnsql.com/blog/how-to-import-csv-to-postgresql/
copy us_counties_2010 from 'C:\Users\obella\OneDrive\Desktop\us_counties_2010.csv' with (FORMAT CSV, HEADER,DELIMITER ',');
Use this code instead of that

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.

Error trying rename a file

Hi community!
I have an application in VB.Net, in the user's computer is located in program files.
The users run always the program as an Administrators.
But in some cases; when the program try to rename a file in the program files the program throws the following exception:
The given path's format is not supported.
SOURCE = System.Security.Util.StringExpressionSet.CanonicalizePath
Also, happens when I try to copy a file.
The application does the rename or copy automatically and it's the same name for all the users
Example:
Rename(vOld, vNew)
FileCopy(vOld, vNew)
This exception only happen in Win7.
Somebody have an idea what is the reason to some users appear this exception?
This will happen when the user provides an invalid file name, for example one that includes colons.
You should validate that the user-entered file name does not contain any of the values in System.IO.Path.GetInvalidPathChars.
All it's my fault!
-_-'
I'm trying to rename this path:
C:\_MyFile.xlsx
To:
C:\MyFile.xlsx
In my computer all works fine because I have the both files (The users only has the file with the underscore).
When the program try to validate it try to rename the file "_C:\MyFile.xlsx" to "C:\MyFile.xlsx"
The exception don't give much information about my error...

SQL Server Database Attach error. The system cannot find the file specified

When im trying to attach database get such error Does Anyone have an idea what can be problem?
On your first picture, I see the med_log.ldf file. On second picture you trying to attach med.ldf. Try to change the name of file in line 3 to med_log.ldf.
Your error message states that it is looking for Med.ldf, not Med_log.ldf.
You need to change the filename in the second part of your restore command to match this filename.
The name of the Log file seems to be incorrect. it should be "Med_log.ldf" instead of "Med.ldf"

Edit the control file in Oracle 10g Release 2

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.