Exporting MS SQL Server 2000/2005/2008 tables to XML

Posted by admin | Uncategorized | Monday 5 October 2009 4:50 am

Let’s talk about the problem, which became the title of the topic.

Production:

The need for the withdrawal of the table on the server in the XML file encoding you want for future needs (analysis, integration of XML into other components and applications, etc.). We use the bat-script.

Difficulties

Lack of support for exports to various encoding tools MS SQL.
SQL Server does not store the encoding XML, where XML-data permanently stored in the database. Therefore, the original XML encoding of fields available for export XML-data. To export a SQL Server uses the UTF-16.
©
The simplicity and speed of use for the various tables and databases.

Steps of implementation

First, we use the utility bcp, which included MS SQL Server (Even in the Express version). Podrobree.
Because of its capabilities, we need only the result output request to a file.
The values of keys on the example:
bcp “SELECT * FROM DB.SCHEMA.TABLE FOR XML AUTO, ROOT ( ‘ROOT’)” queryout temp.xml-w-S% SERVERNAME%-U% DBUSER%-P% DBPASS%

Description of team:

SELECT query to retrieve all data from the table (the full name).
XML AUTO is responsible for converting the result to an XML tree.
ROOT appoints the root element in this tree
queryout specifies the output file
-w specifies the use of Unicode for mass copying
-S name of the server instance
-P password
-U user

Using this command we get the XML file without a header in the UTF-16.
It is necessary to add a title and make the correct xml encoding.
Create a template header xml_header.xml with the contents:

* This source code was highlighted with Source Code Highlighter.

Now it will be sufficient to execute the command
copy xml_header.xml + bcp_out.xml result.xml
and get a valid XML document.

To convert the encoding is going to use iconv, any implementation. I chose the most compact and portable solution for Windows, written in Win32 API from Yukihiro Nakadaira.

So, the script file:

@ echo off

if "% 1" == "" (
The absence rem options
echo Use with: db_name db_table [out_file]
exit / b 1
)

if "% 2" == "" (
echo Use with: db_name db_table [out_file]
exit / b 1
)

rem We read the settings from the file settings.txt, which must be located in
rem the same directory as the bat-file. If you can not parse configuration --
rem exit with a nonzero return code.
call: read_settings% ~ dp0settings.txt | | exit / b 1

set DBNAME =% 1
set DBTABLE =% 2
set OUTFILE =% 3

echo;
echo ====== ECHO SETTINGS FROM CONFIG ======
echo;
echo ServerName:% SERVERNAME%
echo Schema:% SCHEMA%
echo Out codepage:% OUTCP%
echo User:% DBUSER%
echo Pass: ********
echo Iconv path:% ICONVPATH%
echo;
echo =======================================
echo;
echo ====== ECHO SETTINGS FROM CMD =========
echo;
echo DB Name =% 1
echo DB Table =% 2
echo Output file =% 3
echo;
echo =======================================
echo;
echo ====== CALL TO BCP UTIL ===============
echo;
call: bcp_call
echo;
echo ====== CALL TO ICONV ==================
echo;
call: iconv_call
echo;
echo =======================================
echo;
echo See the log \ log.txt for details
exit / b 0

rem
rem Function to read the settings from a file.
rem Login:
rem% 1 - file name settings
: read_settings

set SETTINGSFILE =% 1

rem Check file exists
if not exist% SETTINGSFILE% (
echo FAIL: No such file% SETTINGSFILE%
exit / b 1
)

rem Processing file c settings

for / f "eol = # delims == tokens = 1,2"%% i in (% SETTINGSFILE%) do (
set%% i =%% j
)

exit / b 0

rem
rem function to access the database
: bcp_call

bcp "SELECT * FROM% DBNAME%.% SCHEMA%.% DBTABLE% FOR XML AUTO, ROOT ( '% DBTABLE%')" queryout temp.xml-w-r ""-S% SERVERNAME%-U% DBUSER% -- P% DBPASS%> log \ rawlog.txt

rem encoding the log in normal encoding
% ICONVPATH%-f cp866-t cp1251 log \ rawlog.txt> log \ log.txt
del log \ rawlog.txt

copy lib \ xml_header.xml + temp.xml temp2.xml> nul
del temp.xml

echo Finished.

exit / b 0

rem
rem Function conversion
: iconv_call

rem a default value of the output encoding
if “% OUTCP%” == “” (
set OUTCP = CP1251
)

rem a default value of the output file
if “% OUTFILE%” == “” (
set OUTFILE = out \% DBTABLE%. xml
)

if not exist% ICONVPATH% (
echo FAIL: Check Iconv path!
exit / b / 1
)

% ICONVPATH%-f UTF-16-t% OUTCP% temp2.xml>% OUTFILE%
del temp2.xml

echo Finished.

exit / b 0

* This source code was highlighted with Source Code Highlighter.

A command-line pass: DatabaseName tbl_name [output file]
The rest of the configuration prescribes in settings.txt:

# Server Name
SERVERNAME = WIND \ SQLEXPRESS
# Name of scheme
SCHEMA = dbo
# Name the output encoding
OUTCP = CP1251

# User
DBUSER = dzhon
# User password
DBPASS = 123

# Path to iconv.exe
ICONVPATH = lib \ win_iconv.exe

For the logic in the XML file created 3 functions.
First parses the configuration, the second is bcp, the third - iconv for the resulting file.

Conclusion

Immediately, I note that by default uses CP1251, and the log of the bcp is encoded in it the same. This is done for the convenience of it is in Windows, and not some other religious preference. I remember the days when Windows XP betrayed krokozyabry when calling a simple route PRINT in the descriptions of the interfaces … So I myself prefer to always and everywhere UTF-8. However, the script is flexible enough to change the encoding output, though will have to ask in xml_header.xml another value.

Download the working version of the solution here (13 Kb).

For SQL Server 2000 will have to make some changes due to the fact that the concept of the scheme (in terms of container facilities) has been introduced only in 2005.

You can also see the material on writing bat files, which had been dragged from parsing configuration.

Thank you for your attention, I hope someone can help.
Moved to a thematic blog in the presence of karma, however, you decide.



Check out the analysis of pantswalker.net, 3t.cn, interpark.com, bollyfm.net, land.to, animefreak.tv, asiafriendfinder.com, vuku.ru, 91.cn, bloggang.com - and much more

Problems of Google

Posted by admin | Uncategorized | Saturday 3 October 2009 7:20 am

The reason for suspicion was concluded in 2008 an agreement between Google and major publishing houses and authors of the United States.

Recall that in late 2005, the American publishers and authors have sued Google, accusing the company of massive copyright infringement. Then the cause of complaint was the search service Google Book Search, the bases of which are digital copies of books. Service provides libraries access to electronic books without the express consent of the authors.

Only the fall of 2008 this conflict was resolved. For Google, the claim costs were $ 125 million that went to the establishment of the Register of rights to the books (Books Rights Registry). Any writers can make their work in this register and receive money for their use. Funds for payments received from participating in Google libraries and universities, as well as from sales of electronic copies of books, advertising and other sources.

According to U.S. Department of Justice, the terms of this agreement conflict with U.S. antitrust laws.

logo Problems of Google
Check out the analysis of psu.edu, techguy.org, besplatnoexxx.com, golflink.com, filebank.co.jp, adsonar.com, sahibinden.com, technorati.com, joins.com, meatmembers.com - and much more

How to make a screenshot

Posted by admin | Uncategorized | Sunday 20 September 2009 5:08 am

Wondering how to make a screenshot? Take a look at Pict image hosting software solutions: Pict FireFox extension and Pict Uploader for Windows. Both applliactions allow you to capture screenshots, save them in different formats and automatically upload them to Pict image hosting.

YouTube is counting on a deal with movie studios

Posted by admin | Uncategorized | Thursday 17 September 2009 10:12 am

7 YouTube is counting on a deal with movie studios

YouTube is counting on a deal with movie studios to release new movies available on the Internet.

Inneresting.

According to those familiar with the plan, negotiations are already underway with Lionsgate, Sony, Warner Bros and MGM, which already has ad deals with the company.

The idea would be similar to Itunes, where you can view the rent for 24 hours for about $ 1.99-$ 3.99.

It sounds like a good idea, but how many people actually make the transition from ITunes streaming video giant?

There’s Gotta Be an element of competition somewhere, right?

Would U watch a movie rental on YouTube??

SearchMe May Go Offline Tomorrow

Posted by admin | Uncategorized | Thursday 10 September 2009 3:31 am

We have last week wiki article describing “SearchMe May Go Offline Tomorrow (Updated: Offline Now)” at number one tech site Washington Post. IT guy brings on a whole bunch of awesome issues & programming magazines about “YouTube Enters The Stream” (hifi-forum.de), “VMWare Acquires SpringSource” (travian.in wiki), “Why Google Employees Quit (torrentdownloads.net wiki)” and “Obama’s Crowdsourced Resolutions For 2009 (fulldls.com profile)”. You can get tons of fresh IT articles & documentation on cool projects.Hubs, personal blogs, services, media websites, startups, news sites are fully reviewed at “AIM Embraces The Lifestream”. Have a good reading and bookmark us.

The Europas Liveblog 2009

Posted by admin | Uncategorized | Wednesday 9 September 2009 10:17 am

Here is fresh wiki text where author talks about “The Europas Liveblog 2009″ at ultimate online site Washington Post. Writer writes about several awesome problems & programming problems related to “Deny This, Last.fm” (icicibank.co.in), “The Google Ventures Cheat Sheet” (lawyers.com), “Yazzem Launches Version 2; Improves Latest Activity Among Users (menelgame.pl)” and “How OpenTable Could Actually Matter (game.co.uk)”. You may also download megabytes of brand new geek news & documentation on amazing meetings.Hubs, media websites, news sites, startups, personal blogs, services are fully represented at “Google Latitude: The Video”. Check it out and come back again.

YouTube - Finally HD!

Posted by admin | Uncategorized | Sunday 6 September 2009 9:27 am

22 YouTube - Finally HD!
Well known YouTube media hosting is finally offering High Definition video support we all have been waiting for so long I think! It is great now video is available in such a great quality and it is cool one may leave any comments and have fun.

PingWin Software

Posted by admin | Uncategorized | Friday 4 September 2009 2:07 pm

Russia PingWin Software company announces (via lepoint.fr) development of original scripts, which can be applied in the free Linux operating systems as effective analogs of the well-known typefaces that come with office software products and Microsoft family of operating systems Windows. Set of fonts will be distributed under a free license.

The project was named PingWi Typography (via einslive.de). In accordance with the modern trend of typographic font in all its components is supported by stylistic unity that distinguishes the modern development called supergarniturami. For the convenience of users for a set of headsets PWT selected names: PWT Tahion, PWT Arion, PWT Courant, PWT Verde, PWT Timer. Pipeline headset can be used independently in all components of OpenOffice.org 3 in the presence of FreeType 2.

In the near future will be announced closed beta testing to gather suggestions and comments on fonts PWT Tahion, PWT Arion (via 19lou.com) and PWT Verde. All those wishing to be sent to the original fonts OTF and TTF, as well as documentation for testing. Open testing will begin within a 1.5-2 months after the removal of the first comments. Output the first part of the package (PWT Tahion, PWT Arion and PWT Verde) is expected in late 2009, PWT Timer and PWT Courant - in 2010.

do-we-have-enough

Posted by admin | Uncategorized | Monday 6 April 2009 6:48 am

do-we-have-enough
(more…)

Mac geek photo

Posted by admin | Uncategorized | Monday 6 April 2009 6:48 am

365.91

Next Page »
We will help you to find photo, video and media information!