Importing Data From Excel File Into SQL Server

Apr 9, 2000

Can anybody please give an example of how to import data from an Excel file to SQL Server in a VB Application using DTS.

I am particularly facing problems creating the connection for the Excel file. An example for that would be aprticularly helpful.

Thanks in adv,
Rahul.

View 1 Replies


ADVERTISEMENT

Importing Data From An Excel File

Nov 13, 2007

Hi all,
I am trying to export data from an excel file to SQL Server database for reporting. Unfortunately I get the following errors.


[OLE DB Destination [54]] Error: SSIS Error Code DTS_E_OLEDBERROR. An OLE DB error has occurred. Error code: 0x80040E21. An OLE DB record is available. Source: "Microsoft SQL Native Client" Hresult: 0x80040E21 Description: "Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done.".

Could some one bail me out of this bug.

Regards,

Ronaldlee








View 1 Replies View Related

Error When Importing Data From Excel File

Aug 22, 2006

Hi!

This is what i'm doing:

IF EXISTS (SELECT srvname FROM master.dbo.sysservers srv WHERE srv.srvid !=

0 AND srv.srvname = N'ExcelSource')

EXEC master.dbo.sp_dropserver @server=N'ExcelSource', @droplogins='droplogins';

-
EXEC master.dbo.sp_addlinkedserver
@server = 'ExcelSource',
@srvproduct = 'Excel',
@provider = 'Microsoft.Jet.OLEDB.4.0',
@datasrc = @Chemin,
@provstr = 'Excel 8.0';


EXEC master.dbo.sp_addlinkedsrvlogin
@rmtsrvname = 'ExcelSource',
@useself = false,
@locallogin = NULL,
@rmtuser ='ADMIN',
@rmtpassword = NULL;

set @NomServ = 'ExcelSource';

This create a linkedServer to read my ExcelFile.

Then i'm doing this:

EXEC ('Insert into Elements (No_element, Nom_elem, Desc_elem, Code_grpe_classe, Tps_elem, Code_sgrpe, Code_produit)
Select No_element, Nom_elem, Desc_elem, Code_grpe_classe, Tps_elem, Code_sgrpe, Code_produit
from ' + @NomServ + '...[Elements$];')

This is where i got an error. The error is:
The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "ExcelSource" does not contain the table "Elements$". The table either does not exist or the current user does not have permissions on that table.

I can't figure out what i'm missing. I've add permissions for EVERYONE on the file and on the folder just to be sure and i still have the same error. How can i check if the table [Elements$] exist ?

View 3 Replies View Related

Importing An Excel File And Save Data Into A Database In My Web Account

Aug 30, 2007

Hi everyone, sorry if this message is not supposed to be posted here.
I'm learning asp.net , and would like to know how I can insert data from a excel file into a database on my web account. Pretty much insert/update information in the database using excel file or a access file. 
Thanks a lot in advance

View 3 Replies View Related

Importing Excel File Into Sql Server 2005 In Asp .net Using C#

Dec 14, 2007

Dear friends i want to import excel file into sql server 2005 in asp .net using c# can anyone help me?
rgds,RK

View 7 Replies View Related

Importing Excel File To SQL Server (Opinions Please)

May 18, 2005

Dear All,
I am writing a procedure to import daily the customer excel file to SQL server 2000, I managed to do that where the excel file will be imported directly to the SQL server after creating the new data table, & then I need to read the created table & import it row by row to my original data table.The problem:
I.        The original excel file has the following:a.       a protection passwordb.      The contents has two merged headers (which effecting the import procedure)c.       And last line is a totals line
Before importing the file I have manually to remove (a – b & c)!!
The Solution:
II.     I am trying to find a way to do the above points automatically inside the project.
III.   Also I thought of importing the excel file to a DataGrid first then:a.       Let the user approve the file contents &b.      Remove manually point (I.b.) above (I don’t now how yet, need to try it).c.       Then import the DataGrid the the SQL server.
I think I prefer solution (III), any suggestions are highly appreciated
BR

View 3 Replies View Related

Problem With Importing The Excel File SQL Server 2k5

Jul 11, 2007

I got the following error when importing file to sql server 2005. I reinstalled the MDAC as well.

Please help.



TITLE: SQL Server Import and Export Wizard
------------------------------

An error occurred which the SQL Server Integration Services Wizard was not prepared to handle.

------------------------------
ADDITIONAL INFORMATION:

Exception has been thrown by the target of an invocation. (mscorlib)

------------------------------

The connection type "EXCEL" specified for connection manager "{E3861233-443A-439A-BB8D-2777D84DB343}" is not recognized as a valid connection manager type. This error is returned when an attempt is made to create a connection manager for an unknown connection type. Check the spelling in the connection type name.
({C3728B0D-B172-4246-9B14-6EEDAB60F191})

------------------------------

The connection type "EXCEL" specified for connection manager "{E3861233-443A-439A-BB8D-2777D84DB343}" is not recognized as a valid connection manager type. This error is returned when an attempt is made to create a connection manager for an unknown connection type. Check the spelling in the connection type name.
({C3728B0D-B172-4246-9B14-6EEDAB60F191})

------------------------------
BUTTONS:

OK
------------------------------

View 5 Replies View Related

DTS Error: Importing From Excel File To SQL Server 2000

Nov 30, 2007

 Data for Source Column 15 'Notes' is too large for the specified buffer size. How do I get around this, I can see some of the notes entries are beyond 255 chars so I changed the destination datatype to textI have never seen this error when importing before. What do I do? 

View 1 Replies View Related

SQL Server 2008 :: Importing Excel File Stored In Sharepoint

Feb 23, 2015

I have an excel file that is stored in a sharepoint document library. I am trying to use SSIS to import it into a SQL database. I use the excel connection manager with a sharepoint UNC path. When I run it from BIDS, it runs successfully. When I run it from a job, I get an error

"It is already opened exclusively by another user, or you need permission to view and write its data"

It is definitely not open by anyone else, and I have full permissions to the file. ALSO, the SQL Agent and Service acct which the job runs under, has full permissions to the file. I have tried running it under a proxy account with my user account, but it fails with the same message. Further, I can run a DIR command from a command prompt to list the sharepoint directory contents successfully, but when I run the same command from SSMS using xp_cmdshell, it fails with access denied. Again, the SQL Service acct has full rights to the sharepoint site.

I notice when i browse to the sharepoint document library and try to open the folder with "Open with Windows Explorer", it always asks me to login and I'm thinking that is related to the problem I am having - that it doesn't automatically pick up the windows authentication.

View 3 Replies View Related

Importing Data From Excel To SQL Server

Sep 14, 2004

I have a Excel 2000 column which looks like this:

Column A
23456
234-67
2-56
354899865

When I create a DTS package to import this column, only the values without a hyphen get imported correctly..and a null value will show for the numbers that have a hyphen in it.

I've set my datatype to varchar, float, nvarchar, text, etc in SQL Server 2000...but nothing seems to work. I have also changed the datatype in my excel spreadsheet to text, general, etc.

I've tried so many combinations, I forget which ones I've tested...Anybody have an idea what I should try ?

Thank you

View 3 Replies View Related

TSQL + VBA Excel 2003 - Importing Data From MS Excel 2003 To SQL SERVER 2000 Using Multi - Batch Processing

Sep 11, 2007

Hi,
I need to import an SQL string from MS Excel 2003 to SQL SERVER 2000.
The string I need to import is composed by 5 different several blocks and looks like:



Code Snippet

CommandLine01 = "USE mydb"
CommandLine02 = "SELECT Block ..."
CommandLine03 = "GO
ALTER TABLE Block...
GO"
CommandLine04 = "UPDATE Block..."
CommandLine05 = "SELECT Block..."

The detail of the SQL string is at:
http://forums.microsoft.com/msdn/showpost.aspx?postid=2093921&siteid=1&sb=0&d=1&at=7&ft=11&tf=0&pageid=1



I am trying to implement OJ's suggestion:
http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=2117223&SiteID=1
to use multi - batch processing to import the string to SQL SERVER, something like:




Code Snippet
Dim SqlCnt, cmd1, cmd2, cmd3
'set the properties and open a connection

cmd1="use my_db"
cmd2="create table mytb"
cmd3="insert into mytb"

SqlCnt.execute cmd1
SqlCnt.Execute cmd2
SqlCnt.Execute cmd3

Below is the code (just partial) I have, and I need help to complete it.
Thanks in advance,
Aldo.




Code Snippet
Function TestConnection()
Dim ConnectionString As New ADODB.Connection
Dim RecordSet As New ADODB.RecordSet

ConnectionString = "Driver={SQL Server};Server=myServer;Database=myDBName;Uid=UserName;Pwd=Password"
ConnectionString.Open

CmdLine01 = " USE " & myDB
CmdLine02 = " SELECT ACCOUNTS.FULLNAME FROM ACCOUNTS" ...

CmdLine03 = "GO
ALTER TABLE Block...
GO"

CmdLine04 = "UPDATE Block..."
CmdLine05 = "SELECT Block..."

RecordSet.Open CmdLine01, ConnectionString
RecordSet.Open CmdLine02, ConnectionString

ConnectionString.Execute CmdLine01
ConnectionString.Execute CmdLine02

'Retrieve Field titles
For ColNr = 1 To RecordSet.Fields.Count
ActiveSheet.Cells(1, ColNr).Value = RecordSet.Fields(ColNr - 1).Name
Next

ActiveSheet.Cells(2, 1).CopyFromRecordset RecordSet

'Close ADO objects
RecordSet.Close
ConnectionString.Close
Set RecordSet = Nothing
Set ConnectionString = Nothing

End Function






View 7 Replies View Related

ASP .NET--Problem With Importing Data From Excel To SQL Server..

Feb 21, 2008

Is there any way to import the excel data to SqlServer 2000 without using OleDb Connection in the code...??
Help Me with this??
Thanks in advance..

View 5 Replies View Related

Problem In Importing Data From Excel To Sql Server

Apr 19, 2007

I have excel file that has field named Purpose. Its max length is 400 character. I import this file to sql server database table. And also i change the purpose field in sql server database table with nvarchar 400. But when i run this job, it gave me error message:

Error at source for row number 1215. Errors encountereed so far in this task: 1.
Data for source column 18 ('Purpose') is too large for the specified buffer size.

What should i do so that i still can import the data from excel to sql server database?

Thanks for your help.

View 1 Replies View Related

Importing Data From Excel To SQL SERVER Database

Aug 23, 2006

Hello all:

I have gone through most of the question posed by people, about importing data from EXCEL sheet to some table using SQL server database. I have a slight variation of this problem.

My excel file contains some information apart from the normal data.
Lets say some 5-6 lines always gives me some info about the data, like its purpose, client info, date etc...
After this INFO my actually data start, which I want to load into table.

I have found some wizard for the same, "EMS SQL MANAGER 2005", which supports most of the file formats, and load data into the database.

But we are planning to not use this tool, instead everything should be done using TSQL.

If somebody can please gives me some idea how this problem can be tackle, it would be a great help. We won't be using any Third party tools, like scripting etc...

We want to stick with just TSQL for this problem.

Thanks a bunch,
sabegh

View 1 Replies View Related

Importing Excel Data Into New Table In MS SQL Server

Jul 10, 2007

I have installed SQL Server Managemert Server Express .... I am wondering how to import data from an excel spreadsheet?



.. Silent Running

View 3 Replies View Related

Importing Excel Data Into SQL Server 2005 With A Twist!

Jun 11, 2007

Hi,
I would like to import an Excel spreadsheet into SQL Server 2005. I can do this quite easily using the Import/Export wizard, and have each row in the spreadsheet transfer to a new row in the database table.
However, I want to import the first few columns of the spreadsheet row into one table (called Products), but put the remaining columns into a related, three-column table, called Product_Details. In the Product_Details table, one column would hold the spreadsheet column value, the other column would be a FK integer value linked to the PK in the Products table, and the third column the primary key as normal.
So, somehow, I would need to get hold of the primary key value when the first spreadsheet columns are inserted into the Products table and then insert the remaining columns into the Product_Details table with two values per row - one value being the spreadsheet cell value, the second being the primary key of the new product in the Products table.
TIA,
Graham.

View 1 Replies View Related

Importing Data From Excel 2003 To Sql Server 2005

Sep 3, 2007

Hi all. I want to export data from excel 2003 to sql server 2005. I am using the following script:
EXEC sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
EXEC sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
Insert into Pamphlet
Select * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0',
'Excel 8.0;Database=C:Pamphlet.xls;HDR=YES', 'SELECT * FROM [Sheet3$]')
But it is giving the following error:
Msg 7399, Level 16, State 1, Line 2
The OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)" reported an error. The provider did not give any information about the error.
Msg 7303, Level 16, State 1, Line 2
Cannot initialize the data source object of OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)".
The above script is working fine with Excel 2002 but not with 2003. Can someone please provide me exact script of importing data from excel 2003 to sql server 2005. I have also tried the Linked server option but it is still giving the same error.
Please help me.  
 
 

View 1 Replies View Related

Importing Data From Excel Sheets Into SQL Server Database

Feb 15, 2006

Hi,
Would like some help on how do I go about coverting an Excel File with columns of info into my SQL Server Database. The excel file will be uploaded from a user from my web application. I completely have no idea on where to start so any form of help is much appreciated thanks.

View 3 Replies View Related

Getting Null Values While Importing Data From Excel Sheet To Sqql Server

Aug 16, 2007

Hai Friends,
Actually i want to import excel sheet in to sql server tables. I am writing the following query                                                                                           SELECT * FROM OPENROWSET('Microsoft.Jet.OLEDB.4.0', 'Excel 8.0;Database=C:Book1.xls','SELECT * FROM [Sheet1$]') and able to retireve the data but the problem is the data present in the excel sheet is





Username
password

hello
12345

12345
hello

hai-123
haihai

haihello
hello-123
Once i run this query i am getting it as                                                                                                                                                              
Username Password                                                                                                                                                                                           hello NULLNULL hellohai-123 haihaihaihello hello-123can anybody please help me out in this case and how to solve this problem and if you have any piece of code please pass it on to me and i am in very urgent need waiting for your replies thanks in advance.

View 2 Replies View Related

Importing And Excel File

Jul 31, 2007

How do i import a Excel file into a table i have created in my database in SQL server 2005??? 

View 10 Replies View Related

Memo Data Type Import Error While Importing Data From Access File Into SQl Server 2005

Sep 10, 2007

I have one column in SQL Server 2005 of data type VARCHAR(4000).

I have imported sql Server 2005 database data into one mdb file.After importing a data into the mdb file, above column
data type converted into the memo type in the Access database.

now when I am trying to import a data from this MS Access File(db1.mdb) into the another SQL Server 2005 database, got the error of Unicode Converting a memo data type conversion in Export/Import data wizard.

Could you please let me know what is the reason?

I know that memo data type does not supported into the SQl Server 2005.

I am with SQL Server 2005 Standard Edition with SP2.

Please help me to understans this issue correctly?

View 4 Replies View Related

Importing Excel File With A Field?

Jul 23, 2014

I am import a file from Excel that has dates as this type 10:00 AM. When I import it into SQL, the field looks like this....

1899-12-30 10:00:00.000

How can I import this field to stay like 10:00 AM?

View 1 Replies View Related

Importing Excel File In SSIS

Aug 8, 2007

Okay... I am now about to pull my hair out: something that worked VERY EASILY in Server 2000 doesn't seem to work at all in 2005. I am trying to pump an Excel table into a 2005 database. I go into the Visual Studio Integration Services Project (this is so much easier... cynicism) and set up a project. I have my data source (Excel), I have my destination (SQL Natve Server, database). I set it up the same way that it worked (perfectly) in DTS and I run it... it grinds away and reports back that all is well... no errors. I go looking for the table... not there. I try with an SA login VS windows authentication... not there. I try with a different table... no there. I try with a different database... not there.

I am certain you can imagine the frustration... that is, if you are a user, not a programmer at Microsoft.

Okay, okay... I won't launch in to abuse here... but hey, how do I make this very complicated process now work?

Thanks...

View 3 Replies View Related

Importing Excel File Into Database

Sep 4, 2007

Hi, I am very new to ssis, I am trying to set up a package that I can set to run every hour or so, what it will do is look for all excel files in a certain folder and import them into a table on an sql server.

I managed to get it working but my problem is that my data is survey answers and some columns contain a comment.
I get these files on a weekly basis and some weeks the length of the longest comment makes ssis want to use a different data type for the comment column (sometimes it wants DT_NTEXT, other times it wants DT_WSTR).
as this column is filled out by a human I guess aposrtophies and other characters may affext this as well.

when I made the data flow task, I used the wizard on a file which contained about 8 weeks worth of data. when I use 1 weeks worth of data where the comment length is very low, the task gives a validation error saying the metadata is out of sync. if I go back and set the data type for that column to DT_WSTR and rerun the task, it works but then when it tries to process a different weeks worth of data it will fail again

here is an example of an error I get when it thinks the data type is wrong.
[Source - 'raw data$' [1]] Error: The output column "Question ID50# (Verbatim)" (439) on the error output has properties that do not match the properties of its corresponding data source column.

I played around with the data types for a while and managed to get it to process the first file and then try to process the secondfile, in the second file it got around the validation but then got this error:
[Source - 'raw data$' [1]] Error: Failed to retrieve long data for column "Question ID3# (Verbatim)".

is there a way to make it recalculate the data types by itself for each excel file?


I am stuck trying to figure this one out.
sorry if I havent provided enough information, I am not sure which direction to head with this

View 4 Replies View Related

Error Importing Excel File

Mar 7, 2006

When ever importing a excel file or flat file, I get an Unhandled exception error and the event log reads a .Netframework error ID 1000.

Checking the database I was importing into, I find that the table was created with the columns, but no data within the columns.

The import wizards report 509 row copyed before crashing with the Handle error, where a dialog box appears allowing debug or close.

Can anyone help?

I include the logged errors.

Event Log

.NET Runtime 2.0 Error
Event ID: 1000

Faulting application dtswizard.exe, version 9.0.1399.0, stamp 434f5e2a, faulting module dtspipeline.dll, version 2005.90.1399.0, stamp 434f5dbc, debug? 0, fault address 0x0004ba38.

For more information, see Help and Support Center at http://go.microsoft.com/fwlink/events.asp.

0000: 41 00 70 00 70 00 6c 00 A.p.p.l.
0008: 69 00 63 00 61 00 74 00 i.c.a.t.
0010: 69 00 6f 00 6e 00 20 00 i.o.n. .
0018: 46 00 61 00 69 00 6c 00 F.a.i.l.
0020: 75 00 72 00 65 00 20 00 u.r.e. .
0028: 20 00 64 00 74 00 73 00 .d.t.s.
0030: 77 00 69 00 7a 00 61 00 w.i.z.a.
0038: 72 00 64 00 2e 00 65 00 r.d...e.
0040: 78 00 65 00 20 00 39 00 x.e. .9.
0048: 2e 00 30 00 2e 00 31 00 ..0...1.
0050: 33 00 39 00 39 00 2e 00 3.9.9...
0058: 30 00 20 00 34 00 33 00 0. .4.3.
0060: 34 00 66 00 35 00 65 00 4.f.5.e.
0068: 32 00 61 00 20 00 69 00 2.a. .i.
0070: 6e 00 20 00 64 00 74 00 n. .d.t.
0078: 73 00 70 00 69 00 70 00 s.p.i.p.
0080: 65 00 6c 00 69 00 6e 00 e.l.i.n.
0088: 65 00 2e 00 64 00 6c 00 e...d.l.
0090: 6c 00 20 00 32 00 30 00 l. .2.0.
0098: 30 00 35 00 2e 00 39 00 0.5...9.
00a0: 30 00 2e 00 31 00 33 00 0...1.3.
00a8: 39 00 39 00 2e 00 30 00 9.9...0.
00b0: 20 00 34 00 33 00 34 00 .4.3.4.
00b8: 66 00 35 00 64 00 62 00 f.5.d.b.
00c0: 63 00 20 00 66 00 44 00 c. .f.D.
00c8: 65 00 62 00 75 00 67 00 e.b.u.g.
00d0: 20 00 30 00 20 00 61 00 .0. .a.
00d8: 74 00 20 00 6f 00 66 00 t. .o.f.
00e0: 66 00 73 00 65 00 74 00 f.s.e.t.
00e8: 20 00 30 00 30 00 30 00 .0.0.0.
00f0: 34 00 62 00 61 00 33 00 4.b.a.3.
00f8: 38 00 0d 00 0a 00 8.....



Debug Log

Unhandled exception at 0x2357ba38 in DTSWizard.exe: 0xC000001D: Illegal Instruction.

View 4 Replies View Related

Importing Excel File Into A MS-SQL 2005 Table

Jun 14, 2006

I hope this is the right forum for my question.
I'm developing a website for a Prepaid Calling Cards distributor. Each of the cards they sale have a list of the countries the card is good for. I need to import this data into my countries_rates table. The file they are giving me is an excel file that contain 3 colums (fields)
1- Country-Name
2- Rate
3- Card_$_Price
these files contain aproximaly 400 rows so it will be a hasle to have to insert it manually every week.
In my web application I need to create a form where the user will select the card from a dropdownlist and then find the excel file to be imported for that card.
I would like to know how do I do that with Visual Studio 2005, SLQ 2005 and C#
please direct me to some links where I can learn how to do this or please send me some code snips I can see how is done.
Tia
Charles 

View 2 Replies View Related

Importing An Excel File Dropping Leading Zero...

Mar 6, 2008



I'm importing a excel file in to my database but once the file imports, it drops off the leading zero off of the account number. I have figured out my data types and I'm using (DT_NUMERIC) on that particular field. Is there a way to keep that leading zero?


Shanon

View 4 Replies View Related

Importing Excel File Into 2012 That Is On Oracle VM?

Jun 23, 2015

I am currently trying to migrate a excel file into SQL 2012 database on an Oracle Virtual Box VM. I am new to SQL and this type of IT in general.

View 3 Replies View Related

Error While While Importing Excel File Into SQL2005

Nov 6, 2007



I am using the import tool to import a small excell file into SQL.
I am getting the following error

Error 0xc00470fe: Data Flow TAsk: The product level is insufficient for componene "source - Current_customer$" (1)

The file name I am importing is Current_customer, which contains 4 fields
Id
last
first
zip

View 3 Replies View Related

(Urgent)Question About Importing A Excel File

Oct 4, 2007



I have a excel file which contains 4 columns and have the same number of columns in my SQL server database...

i want to add a column in sql server which is Rownumber and it has int indentity...

But when i insert the data in to the sql server database this is error i am getting in my.net program

Received an invalid column length from the bcp client for colid 1.

any help will be appreciated.

Regards
Karen

View 1 Replies View Related

Integration Services :: Importing Excel File Into Table

Sep 24, 2015

'm getting the following error when trying to import an Excel file into SQL..I'm using SQL Server 2014 Express

- Validating (Error)
Messages
Error 0xc00470b6: Data Flow Task 1: The LocaleID 0 is not installed on this system. (SQL Server Import and Export Wizard)

Error 0xc004706b: Data Flow Task 1: "Source - Sheet1$" failed validation and returned validation status "VS_ISBROKEN". (SQL Server Import and Export Wizard)

Error 0xc004700c: Data Flow Task 1: One or more component failed validation. (SQL Server Import and Export Wizard)

Error 0xc0024107: Data Flow Task 1: There were errors during task validation. (SQL Server Import and Export Wizard).

View 4 Replies View Related

Integration Services :: Importing Excel File Via SSIS Error

Nov 2, 2015

We have a 2014 SQL Server.  I have a SSIS package written in VS 2008 where I am simply importing an .xlsx into an existing table via a mapped drive.  I have it working on my development machine using the 2007 Access 32 bit driver from [URL].....  Our DBA is trying to schedule the package to execute on a schedule job on the 2014 server and we received an error. He installed the 32 bit driver and still getting the error.  I set the package to run in 32 bit and we are still getting the error.

Date                      10/30/2015 2:51:18 PM
Log                         Job History (BD_ISS_Websites_New1)
Step ID                 1
Server                   ETSSQL2014DEV
Job Name                            BD_ISS_Websites_New1
Step Name                         ISSWebsite
Duration                              00:00:01

[code]....

View 3 Replies View Related

SQL Server 2008 :: Getting Error In BCP When Importing Comma Delimited Data File

Sep 3, 2015

I am struggling on using bcp to import data. Here is my steps:

1. I created a Test database on my localhost
2. In the Test database, I created a Test table, the query is here for your convenience:

CREATE TABLE [dbo].[Test](
[id] [int] IDENTITY(1,1) NOT NULL,
[network_group_name] [varchar](128) NULL,
[IP] [varchar](15) NULL,
[OS] [varchar](128) NULL,

[Code] ....

I then create the format file used in bcp:

bcp Test.dbo.Test format nul -c -t, -f C:RXieSQLTest.fmt –T

Here is the format file:

9.0
8
1 SQLCHAR 0 12 "," 1 id ""
2 SQLCHAR 0 128 "," 2 network_group_name SQL_Latin1_General_CP1_CI_AS
3 SQLCHAR 0 15 "," 3 IP SQL_Latin1_General_CP1_CI_AS

[Code] ...

The data file is called 20150902FullTest.rpt and the first couple lines (first line is the header and followed by two rows) are posted here:

network_group_name,IP,OS,App_Name,vuln_name,host_score,recordswritten
Domestic,10.216.56.88,Windows XP SP3,Adobe / Macromedia Flash Player,APSB14-17: Adobe Flash Player CVE-2014-0537 Vulnerability,4350,2015-09-01 09:55:07.720
Domestic,10.216.56.88,Windows XP SP3,Adobe / Macromedia Flash Player,APSB14-17: Adobe Flash Player CVE-2014-0539 Vulnerability,4350,2015-09-01 09:55:07.720

With the format file and the data file, I use the following bcp command:

bcp Test.dbo.Test in C:RxieSQL20150902FullTest.rpt -f C:RxieSQLTest.fmt -T

I got the following error messages:

Starting copy...
SQLState = 22005, NativeError = 0
Error = [Microsoft][SQL Native Client]Invalid character value for cast specification
SQLState = 22005, NativeError = 0
Error = [Microsoft][SQL Native Client]Invalid character value for cast specification

[Code] ...

I do want to mention here is the rpt file contains three BOM characters EF BB BF at the beginning of the file.

View 9 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved