Export MS SQL 7 Server tables having TEXT fields to an ASCII file

Hi,
We are developing an application that uses MS SQL 7 database. The database contains 100-500 thousand records. The application needs to be able to save the database to a text file on user request and we also have to be able to reproduce the database from the saved text file (kind of syncronisation on the client).

The database contains TEXT fields as well. We are looking for a way to export the database to the text file.

The problem is that the TEXT fields can contain any type of characters. So we don't think we can use the BCP tool because it's not possible to define any delimiter that does not appear for sure in the TEXT field.

We were also thinking of solutions like replacing all " characters to "" in  the TEXT field and put a " in the beginning and the end of the field but there does not seem to be any REPLACE function for TEXT fields to accomplish this.

Iterating through the table records and fields and exporting them one by one seems to be the only solution but it's not too fast.

Do you have experience with this problem?

Thanks,
Balazs
brevaiAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Melih SARICAOwnerCommented:


why dont u use a specific delimeter for Example <rowdelimeter> or <fielddelimeter>

like
bcp msdb.dbo.sysjobsteps out "c:\test.txt" -c -U"Username" -P"password" -t"<fielddelimeter>" -r"<rowdelimeter>"


Melih sARICa
0
brevaiAuthor Commented:
Because the table also contains TEXT fields (containing for example word documents) and we can't assume that the delimiter we chose won't occur in the TEXT field. And from then on the exported table's structure is messed up in the exported file and it can't be imported anymore.

Balazs
0
Melih SARICAOwnerCommented:
if i were  u i would try to use a guid for a field delimeter

everytime u send data send a format file with text data

create a GUID for each data Export.. it cant be produced anywhere else and again..
so it ll protect u

If  think that its not the solution

u must copy data to an Access file and then Send it to ur customer


Melih SARICA


0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

Alan WarrenApplications DeveloperCommented:
Hi Balazs

have you considered exporting as XML?

Persisting an ADO Recordset to XML
http://www.vbxml.com/xml/guides/developers/ado_persist_xml.asp

Alan

0
brevaiAuthor Commented:
Hi Alan,

The solution you have provided for exporting the database works fine on the server. We are exporting the database to XML tables.

Now our next problem is that we need to import the database on the client.

Currently we are using an MS Access database on the client. We have managed to load the XML file into a recordset using the LoadFromFile method. But then we don't manage to save the records to a table without looping through them. Do you have a solution for that?

We are also considering to move to SQLite on the client. Any solutions here?

Thanks,
Balazs
0
Alan WarrenApplications DeveloperCommented:
Hi Balazs

I don't have a solution other the one you mentioned, I believe sql server has some better ways of doing this, with things such as the For XML clause, not done much in this area though.

The following is how I parse ADO - persited XML into a Jet catalog.

' The main thing we have going for us that the field names and types in the XML
'  are the same as the field names and types in the target table
' If they aren't then it is the old steam method :(


' Instantite an ADO recordset for the target table
' Instantiate an ADO recordset from the source XML

' Loop through



With rs
  .AddNew
  For Each fld In rsEmail.Fields
    'ProgCtrl_One.Value = ProgCtrl_One.Value + 1
    Dim sFieldName As String
    sFieldName = fld.Name
    If fld.Value = "" Then
        .Fields(fld.Name).Value = Null
    Else
        .Fields(fld.Name).Value = fld.Value
    End If
    Next fld
    .Update
End With


Re: Sql server and XML:
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20971190.html#10943238
http://www.experts-exchange.com/Databases/Microsoft_SQL_Server/Q_20806061.html#9804618

Success with your app!


Alan
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Databases

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.