Welcome to the { mindfrost82.com } forums.

You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact us.

Go Back   { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > Databases > General SQL Server Support

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 07-26-2008, 04:50 PM
FutureShock
 
Posts: n/a
Having problems using BCP for CSV output

I have been using SQL Server 2005 for a total of 2 days and am trying to
transfer table data from one server to another.

For whatever reason the original operator only gave us the DB in a BAK
file. The new server for security purpose won't accept that for a
restore unless it was made on their server.

I installed 2005 express and was able to restore on my computer. I was
then able to brute force recover the table 'structure' on the new server.


Now I need to recover the data however I need to do this with either a
brute force SQL insert or import a CSV.

So maybe if someone can help me with 2 questions. Is there a way to
output an SQL insert statement that includes the data? So far I only get
a template insert.

#2 I was able to get BCP and xp_cmdshell running but when I run the
samples I see on the net I only get the BCP syntax table in the pane,
which I think is telling me I am doing something wrong.

Here is the code I am using just to see if I can get it working.that I
got from the site:

http://www.simple-talk.com/sql/datab...ed-procedures/

**********************************************
declare @sql varchar(8000)

select @sql = 'bcp master..sysobjects out
c:\bcp\sysobjects.txt -c -t, -T -S'+ @@servername

exec master..xp_cmdshell @sql
***********************************************

Thanks in advance for any help that may come my way.

Scotty
Reply With Quote
  #2 (permalink)  
Old 07-26-2008, 06:44 PM
Eric Isaacs
 
Posts: n/a
Re: Having problems using BCP for CSV output

There are some third party tools you might consider for helping with
the transfer of the data. Look into the Red-Gate Software's SQL
Compare tool. A trial version will probably do the trick:

http://www.red-gate.com/index2.htm

Yet another option might be to select another host that will allow you
to use an existing SQL Server database.

As far as the BCP syntax, you were missing a space after the uppercase
S. I was able to test this script successfully:

--------------------------------------------------------
DECLARE @sql VARCHAR(8000)

SELECT @sql = 'bcp master..sysobjects out c:\sysobjects.txt -c -t, -T -
S ' + @@servername

EXEC master..xp_cmdshell @sql
--------------------------------------------------------

-Eric Isaacs


Reply With Quote
  #3 (permalink)  
Old 07-26-2008, 08:09 PM
Plamen Ratchev
 
Posts: n/a
Re: Having problems using BCP for CSV output

You can use these scripts by Narayana Vyas Kondreddi to generate INSERT
statements for your data:
http://vyaskn.tripod.com/code/generate_inserts_2005.txt
http://vyaskn.tripod.com/code/generate_inserts.txt

HTH,

Plamen Ratchev
http://www.SQLStudio.com

Reply With Quote
  #4 (permalink)  
Old 07-26-2008, 08:27 PM
Erland Sommarskog
 
Posts: n/a
Re: Having problems using BCP for CSV output

FutureShock (futureshock@att.net) writes:
> I have been using SQL Server 2005 for a total of 2 days and am trying to
> transfer table data from one server to another.
>
> For whatever reason the original operator only gave us the DB in a BAK
> file. The new server for security purpose won't accept that for a
> restore unless it was made on their server.


I think you should look for a new hosting service, and tell this service
that you are no longer interested in them.

The absolutely best way to move a database between one server to another
is through backup/restore. To wit, this reduces the risk that something
gets mangled in the copying.

Security issues? Of course, the database could include that is malicious
to the server, if their procedures are open to SQL injection. But it
would be no different if you load the server from scripts.

If you want to pursue this operator, you can try the Database
Publishing Wizard,
http://www.microsoft.com/downloads/d...1C5-BF17-42E0-
A410-371A838E570A&displaylang=en

It's not a bad idea to supplement with Red Gate's SQL Compare and SQL
Data Compare, to check that the wizard did not introduce changes.



--
Erland Sommarskog, SQL Server MVP, esquel@sommarskog.se

Books Online for SQL Server 2005 at
http://www.microsoft.com/technet/pro...ads/books.mspx
Books Online for SQL Server 2000 at
http://www.microsoft.com/sql/prodinf...ons/books.mspx
Reply With Quote
  #5 (permalink)  
Old 07-27-2008, 02:15 PM
FutureShock
 
Posts: n/a
Re: Having problems using BCP for CSV output

Eric Isaacs wrote:
> There are some third party tools you might consider for helping with
> the transfer of the data. Look into the Red-Gate Software's SQL
> Compare tool. A trial version will probably do the trick:
>
> http://www.red-gate.com/index2.htm
>
> Yet another option might be to select another host that will allow you
> to use an existing SQL Server database.
>
> As far as the BCP syntax, you were missing a space after the uppercase
> S. I was able to test this script successfully:
>
> --------------------------------------------------------
> DECLARE @sql VARCHAR(8000)
>
> SELECT @sql = 'bcp master..sysobjects out c:\sysobjects.txt -c -t, -T -
> S ' + @@servername
>
> EXEC master..xp_cmdshell @sql
> --------------------------------------------------------
>
> -Eric Isaacs
>
>

Thanks Eric

That seemed to have fixed my BCP problem and was able to recover most of
the tables. Some of the text in the remaining files have a mixture of
the delimitation marks so I will have to use the SQL insert statements
on those.
I learned a great deal in the last couple days.

Scotty
Reply With Quote
  #6 (permalink)  
Old 07-27-2008, 02:17 PM
FutureShock
 
Posts: n/a
Re: Having problems using BCP for CSV output

Erland Sommarskog wrote:
> FutureShock (futureshock@att.net) writes:
>> I have been using SQL Server 2005 for a total of 2 days and am trying to
>> transfer table data from one server to another.
>>
>> For whatever reason the original operator only gave us the DB in a BAK
>> file. The new server for security purpose won't accept that for a
>> restore unless it was made on their server.

>
> I think you should look for a new hosting service, and tell this service
> that you are no longer interested in them.
>
> The absolutely best way to move a database between one server to another
> is through backup/restore. To wit, this reduces the risk that something
> gets mangled in the copying.
>
> Security issues? Of course, the database could include that is malicious
> to the server, if their procedures are open to SQL injection. But it
> would be no different if you load the server from scripts.
>
> If you want to pursue this operator, you can try the Database
> Publishing Wizard,
> http://www.microsoft.com/downloads/d...1C5-BF17-42E0-
> A410-371A838E570A&displaylang=en
>
> It's not a bad idea to supplement with Red Gate's SQL Compare and SQL
> Data Compare, to check that the wizard did not introduce changes.
>
>
>

I agree with the changing of host but I cannot convince the owner of
such. I was able to use the BCP for most files I will have to explore
the SQL Scripts and wizard for the rest.

Thanks for your help and effort.

Scotty
Reply With Quote
  #7 (permalink)  
Old 07-27-2008, 02:19 PM
FutureShock
 
Posts: n/a
Re: Having problems using BCP for CSV output

Plamen Ratchev wrote:
> You can use these scripts by Narayana Vyas Kondreddi to generate INSERT
> statements for your data:
> http://vyaskn.tripod.com/code/generate_inserts_2005.txt
> http://vyaskn.tripod.com/code/generate_inserts.txt
>
> HTH,
>
> Plamen Ratchev
> http://www.SQLStudio.com

Thanks

I will give these scripts a ringing out.

I am so used to MySQL and admin interface, this stuff hurts my lil mind.

Scotty
Reply With Quote
  #8 (permalink)  
Old 07-27-2008, 05:52 PM
FutureShock
 
Posts: n/a
Re: Having problems using BCP for CSV output

Erland Sommarskog wrote:
> FutureShock (futureshock@att.net) writes:
>> I have been using SQL Server 2005 for a total of 2 days and am trying to
>> transfer table data from one server to another.
>>
>> For whatever reason the original operator only gave us the DB in a BAK
>> file. The new server for security purpose won't accept that for a
>> restore unless it was made on their server.

>
> I think you should look for a new hosting service, and tell this service
> that you are no longer interested in them.
>
> The absolutely best way to move a database between one server to another
> is through backup/restore. To wit, this reduces the risk that something
> gets mangled in the copying.
>
> Security issues? Of course, the database could include that is malicious
> to the server, if their procedures are open to SQL injection. But it
> would be no different if you load the server from scripts.
>
> If you want to pursue this operator, you can try the Database
> Publishing Wizard,
> http://www.microsoft.com/downloads/d...1C5-BF17-42E0-
> A410-371A838E570A&displaylang=en
>
> It's not a bad idea to supplement with Red Gate's SQL Compare and SQL
> Data Compare, to check that the wizard did not introduce changes.
>
>
>

Ok I downloaded this wizard and it worked perfectly. It allowed me to
finish up the rest of my restoration efforts.
Reply With Quote
Reply

  { mindfrost82.com } > Gadget Corner > Tech Newsgroups > Programming > Databases > General SQL Server Support


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are Off
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



All times are GMT. The time now is 11:16 AM.


Powered by vBulletin, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.1.0 ©2007, Crawlability, Inc.
© 1999-2008 mindfrost82.com v11.0


Sponsors:
Mobile Phone | Proxy | Myspace Layouts | Find Local Jobs | Mobile Phone



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114