I have server that needs to process and dump from an SQL database queries and tables into xml format on disk. This needs to be a scheduled task.
Currently using BCP via a scheduled batch file > sql script > xp_cmdshell >bcp, but this error
SQLState = S1000, NativeError = 0
Error = [Microsoft][SQL Server Native Client 10.0][SQL Server]Warning: Server data (172885 bytes) exceeds host-file field length (65535 bytes) for field (1). Use prefix length, termination string, or a larger host-file field size. Truncation cannot occur
for BCP output files.
is troubling me in the log files. I have found no solution online yet. I do not quite understand what the 'host-file field' is referring to. The original table has no column with a value as large as 172885 bytes. The output files are very large, and so far it seems as thought the data is all being written, but there seems to be some garbage at the end of all the xml files.
Performance is important but reliability is the most important for me in this situation.
I have tried recreating the error locally but have been unsuccessful in doing so. The server runs Windows Server 2008 r2.
Any help or explanation/analysis of the error and it's meaning, as well as a recommendation of a simple scheduled solution to dump the sql tables/queries to xml files, would be appreciated.
You should check out the FOR XML PATH syntax introduced in SQL Server 2005:
SQL Server: simple example of creating XML file with T-SQL
What's new in FOR XML in SQL Server 2005
With this, you can easily create fairly nifty XML outputs, including hierarchies, attributes and more
Related
I am using Power Automate to extract XML data from a file that a user uploads to Sharepoint, and am inserting this as an array in a row of a SQL table in a SQL Express Server.
This array is then processed and converted into table data using a stored procedure. All runs smoothly, however when the XML file is larger than 4MB, I get a "max request size length exceeded" error and the XML is not fully inserted into the server.
It is my understanding that this restriction can be adjusted in a true SQL Server, or Azure SQL Server, but because I am in an express server I do not have the capability to adjust the max limit. Is this true?
Also, if there is no workaround for SQL Express, are there other options for me to bulk insert XML using Power Automate or even other tools? I thought about creating XML batches and then reconstructing the full array on the server side but haven't had luck with this so far.
I have a SQL file/SQL string which is about 20MB. SQL server simply cannot accept this file. Is there a limit on the maximum size of the .SQL file or variable which is used to query or insert data into SQL server ?
When I say variable, it means passing a variable to SQL server through some programming language or even ETL tool.
You can use SQLCMD, but I just ran into a 2GB file size limit using that command-line tool. This was even though I had a GO after every statement. I get an Incorrect syntax error once the 2GB boundary is crossed.
After some searching, I found this link:
https://connect.microsoft.com/SQLServer/feedback/details/272757/sqlcmd-exe-should-not-have-a-limit-to-the-size-of-file-it-will-process
The linked page above says that every character after 2GB is ignored. That could explain my Incorrect syntax error.
Yep, I've seen this before. There is no size limit to .sql files. It's more about what kind of logic is being executed from within that .sql file. If you have a ton of quick inserts into a small table ex: INSERT INTO myTable (column1) VALUES(1) then you can run thousands of these within one .sql file whereas if you're applying heavy logic in addition to your insert/deletes then you'll have these problems. The size of the file isn't as important as what's in the file.
When we came across these in the past, we ran the .sql files from SQLCMD . Very easy to do. You could also create a streamreader in C# or vb to read the .sql file and build a query to execute.
SQLCMD: SQLCMD -S [Servername] -E -i [SQL Script]
Was that clear enough? If you post an example of what you're trying to do then I could write some sample code for you.
When I first experienced this problem, the only solution I found was to split the .sql file into smaller ones. That didn't work for our solution but SQLCMD did. We later implemented a utility that read these large files and executed them with some quick c# programming and a streamreader.
Size of the SQL file should be limited by memory available on your PC/workstation. However, if you don't want to use osql and/or third party tool(s), there is a solution for this in the very SSMS. It's called SQLCMD Mode and it enables you to run a SQL file by referencing it, and not really opening it in editor.
Basically, all you have to do is:
In your Query menu select SQLCMD Mode
Look up the path to your called script (large SQL file)
Open up a New Query (or use existing one) and write this code in a new line
:r D:\PathToMyLargeFile\MyLargeFile.sql
Run that (calling) script
If you need to use a variable in your called script, you have to declare it in a calling script. Then your calling script should look like this:
:setvar myVariable "My variable content"
:r D:\PathToMyLargeFile\MyLargeFile.sql
Let's say your called script uses the variable for content that should be inserted into rows. Then it should look something like this...
INSERT INTO MyTable (MyColumn)
SELECT '$(myVariable)'
Pranav was kind of on the right track in referencing the Maximum Capacity Specifications for SQL Server article; however, the applicable limit to executing queries is:
Length of a string containing SQL statements (batch size)1 65,536 *
Network packet size
1 Network Packet Size is the size of the tabular data stream (TDS)
packets used to communicate between applications and the relational
Database Engine. The default packet size is 4 KB, and is controlled by
the network packet size configuration option.
Additionally, I have seen problems with large numbers of SQL statements executing in SQL Server Management Studio. (See SQL Server does not finish execution of a large batch of SQL statements for a related problem.) Try adding SET NOCOUNT ON to your SQL to prevent sending unnecessary data. Also, when doing large numbers of INSERT statements, try breaking them into batches using the GO batch separator.
I think your concern comes from trying to open your file in SSMS. Within SSMS, opening a 20mb file would likely be problematic -- no different than trying to open the same file in Notepad or most text editors.
For the record - for other posters - I don't think the questions has anything to do at all with SQL column, table, object, or database sizes! It's simply a problem with using the IDE.
If the file is pure data to be imported, with NO sql commands, try bulk import.
If the file is SQL commands, you're going to need an editor that can handle large files, like Vedit. http://www.vedit.com/ It won't be able to execute the sql. You must do that from the command line using sqlcmd as noted above.
Here are few links,
2 I hope they might be helpful for you
I came through this article on MSDN which specifies "Maximum Capacity Specifications for SQL Server", going through this, I was able to find :
For Sql Server 2012, 2008 R2, 2005 :
Maximum File size (data): 16 terabytes
Maximum Bytes per varchar(max), varbinary(max), xml, text, or image column: 2^31-1 Bytes (~2048 GB)
For more details on Maximum Capacity Specifications for SQL Server, refer:
For SQL Server 2012:
http://msdn.microsoft.com/en-us/library/ms143432(v=sql.110).aspx
For SQL Server 2008 R2:
http://msdn.microsoft.com/en-us/library/ms143432(v=sql.105).aspx
For SQL Server 2005:
http://msdn.microsoft.com/en-us/library/ms143432(v=sql.90).aspx
For Sql server 2000, I am not sure since MSDN seems to have removed related documentation .
It is not clear from your question what the SQL file contains. The solution I suggest below is only applicable if the SQL file you refer to has only insert statements.
The fastest way to insert large amounts of data into SQL server is to use bulk copy functionality (BCP BCP Utility)
If you have SQL Server management studio then you should also have the bcp utlity look in C:\Program Files (x86)\Microsoft SQL Server\90\Tools\Binn (or equivalent).
If you want to use BCP utility then you would need to create a file that contains the data, this can be comma delimited. Refer to bcp documentation on what the file should look like.
For Maximum Capacity Specifications for SQL Server , you can check in here.
http://msdn.microsoft.com/en-us/library/ms143432(v=sql.120).aspx.
if you ask "Is there a limit on the maximum size of the .SQL file or variable which is used to query or insert data into SQL server ?" I will say yes there is a limit for each variabel.and if you want upload file with big size, i recommended you convert your file to varbinary or you can increasing the Maximum Upload Size in your sistem web.
here i give some example http://msdn.microsoft.com/en-us/library/aa479405.aspx
I'm trying to import a large XML data-type in SQL Server 2008, but I'm getting the following error message:
Msg 6365, Level 16, State 1, Line 3
An XML operation resulted an XML data type exceeding 2GB in size. Operation aborted.
Does anyone know what I can do to circumvent this / increase the limit in SQL Server? I finally figured out how to import the Data.Stackexchange.com data-dump, but now it's telling me the XML file is too big for the way I'm importing.
using:
/* Populate the temp table with the comments.xml file */
INSERT INTO #WorkingTable
SELECT *
FROM OPENROWSET(BULK 'd:\so\comments.xml',SINGLE_BLOB) AS data
If you need any other information lemme know. Thanks!
found this site, hope it's not the best resource out there...
EDIT Thanks to #Bummi it seems this is a restriction in SQL Server. Does anyone know how/if I can get around this?
It's limited to 2 GB
Reference Server 2012
SQL Server 2008
SQL Server 2005
I was trying to run a script to create a DB with all the tables and data on a server, which I created using script wizard in SSMS 2008. The destination server is 2005 and since I am unable to just restore a backup, I had to go through this long process which entailed running it through sqlcmd cause it was too large to open in SSMS.
But after running for more than 5 hours, I checked on it and it had the following error:
msg 102 level 15 state 1, incorrect syntax near 'VA'
Now I tried finding the source of the error and looking in the script the only reference to 'VA' are in the data types nvarchar or varchar.
Please help, I really need to deploy this DB.
EDIT
For those who have answered, thanks for the responses. I guess I will have to rerun the script but I would like to know if anyone has any ideas on running the script in SSMS. The script is over 2GB in size since it has to recreate the data and there is no other way to deploy this 2008 DB to a 2005 sql server edition.
Either: you have scripted a SQL Server 2008 only option which can be changed in SSMS (tools..options somewhere)
Or (assuming no other VA strings) the word VARCHAR has truncated to VA. I've had this happen with dynamic SQL: can be a real pain to track down
in SSMS if you double click on the error message in the results pane, it will usually change focus and highlight that line of code. Now, how close that line of code is to the actual error depends on the actual problem, but you should be able to find the line of code it is complaining about.
Really tricky to track these down, but you could either try to generate the script setting the compatibility level for SQL 2005 or use the SQL 2005 tools to generate the script.
I am trying to insert rows into a MySQL database from an Access database using SQL Server 2008 SSIS.
TITLE: Microsoft SQL Server Management Studio
------------------------------
ERROR [42000] [MySQL][ODBC 5.1 Driver][mysqld-5.0.51a-community-nt]You have
an error in your SQL syntax; check the manual that corresponds to your MySQL
server version for the right syntax to use near '"orders"' at line 1
The problem is with the delimiters. I am using the 5.1 ODBC driver, and I can connect to MySql and select a table from the ADO.Net destination data source.
The MySql tables all show up delimited with double-quotes in the SSIS package editor:
"shipto addresses"
Removing the double quotes from the "Use a table or view" text box on the ADO.NET Destination Editor or replacing them with something else does not work if there is a space in the table name.
When SSIS puts the Insert query together, it retains the double quotes and adds single quotes.
The error above is shown when I click on "Preview" in the editor, and a similar error is thrown when I run the package (albeit then from the actual insert statement).
I don't seem to have control over this behavior. Any suggestions? Other package types where I can hand-code the SQL don't have this problem.
Sorry InnerJoin, I had to take the accepted answer away from you. I found a workaround here:
The solution is to reuse the connection for all tasks, and to turn ANSI quotes on for the connection before you do any inserts, with an Execute Sql task that runs the following:
set sql_mode='STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,
NO_ENGINE_SUBSTITUTION,ANSI_QUOTES'
Try using square brackets around the table names. That may help.
EDIT: If you can, I would create views (with no spaces) based on the Access tables, and use those to export. Even if it means building another Access database with linked tables, I think this is your best bet.
I've always struggled with using SSIS with MYSQL directly. Even after installing the ODBC drivers, they just don't play well in data flows. I've always ended up creating linked ODBC connections between SQL Server and MYSQL. I then rely on linked server queries to bring over data. Instead of using a SSIS data flow task, I use an Execute SQL command, usually in the form of a stored procedure that executes an OPENQUERY.
One solution you could do is load the data into a SQL Server database and use it as a staging environment before you load it into the MYSQL database. I regularly move data between SQL Server 2008 and MYSQL and in the past I use to regularly move data between Access and SQL Server.
Another possible solution is to transform the incoming Access data before it loads into the MYSQL database. That may give you a chance to clean up the column names and the actual data that's going through to MYSQL.
Let me know if either of these work for you.
You can locate the configuration setting file my.ini at <<Drive>>:\ProgramData\MySQL\MySQL Server 5.6\my.ini and add "ANSI_QUOTES" to sql-mode.
e.g: sql-mode="STRICT_TRANS_TABLES,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION,ANSI_QUOTES". This should solve the issue while previewing in the SSIS editor.