Executing very large script on Microsoft SQL Server 2008 R2 fails

I was trying to execute very large .sql script in Microsoft SQL Server 2008 R2, that runs on Microsoft Windows Server 2008 R2.

First I tried to copy/paste script into Microsoft SQL Server Management Studio. The server has plenty of memory about 5 GB RAM, and script file is about 150 MB in size and line count is about 1 million, so I do not see problem here. Copy/paste part went ok, however after executing script and after long wait, Management Studio surrendered with “Query completed with errors”:
Microsoft SQL Server Management Studio
------------------------------
Cannot execute script.
------------------------------
ADDITIONAL INFORMATION:
Insufficient memory to continue the execution of the program. (mscorlib)
------------------------------
OK
------------------------------

bl-sql-1

Next I tried various combinations of T-SQL command line tools:
osql -S iDGZdb-dev -i test2.sql -U myuser
sqlcmd -S IDGZDB-DEV -i test2.sql -U myuser
osql -t 100000 -a 65535 ...

Still no success. Various errors appeared in console. Running locally on SQL server:
[SQL Server Native Client 10.0]
Shared Memory Provider: No process is on the other end of the pipe.
[SQL Server Native Client 10.0] Communication link failure

Running on remote machine:
[SQL Server Native Client 10.0]
TCP Provider: An existing connection was forcibly closed by the remote host.
[SQL Server Native Client 10.0]Communication link failure

Tried to search for Google and didn’t find any solution. There were many forums where users ask for help about this issue, but no single answer. Suggested “failed network equipment” is nonsense, if I run script locally, there should be no network involved.

Looked in the System event log under Application logs on the Windows Server where SQL Server resides. Luckily there was an error from the SQL Server:
Log Name: Application
Source: MSSQLSERVER
Date: 2013.02.04. 17:37:41
Event ID: 7836
Task Category: Server
Level: Error
Keywords: Classic
User: N/A
Computer: iDGZdb-dev
Description:
A fatal error occurred while reading the input stream from the network. The maximum number of network packets in one request was exceeded. Try using bulk insert, increasing network packet size, or reducing the size of the request. The session will be terminated.
Event Xml:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="MSSQLSERVER" />
<EventID Qualifiers="49152">7836</EventID>
<Level>2</Level>
<Task>2</Task>
<Keywords>0x80000000000000</Keywords>
<TimeCreated SystemTime="2013-02-04T15:37:41.000000000Z" />
<EventRecordID>223808009</EventRecordID>
<Channel>Application</Channel>
<Computer>iDGZdb-dev</Computer>
<Security />
</System>
<EventData>
<Binary>...some hex stuff...</Binary>
</EventData>
</Event>

But unfortunately, the error reveals very little about the problem. Didn’t get this part of suggestion “… or reducing the size of the request”. The request of 150 MB is too big for the latest edition of MS SQL? Seriously?

Note: Ok, ok… Microsoft SQL Server 2012 is out, and I am not an expert in this area, however, if MySQL can handle scripts in size of gigabytes and Oracle too, then I must be doing something very wrong, but again, then where are all suggestions in the net? Even StackOverflow has only guesses about “network equipment”.

Next, I tried to increase the packet size as suggested in System log message. More statements were executed from the SQL script, however, it still stopped with a memory error:
There is insufficient system memory in resource pool 'internal' to run this query.
Network packet size (bytes): 32576

How I solved this? I surrendered, and instead of wasting time with weird T-SQL error messages, I wrote a little C# script, that executes my file line by line. All of my SQL statements were one-liners. It took me about 1/2 hour to write this script and execute it.

Here is relevant code fragment:
SqlConnection connection = new SqlConnection(Properties.Settings.Default.YourConnectionString);
connection.Open();
System.IO.StreamReader file = new System.IO.StreamReader(yourFilename);
while ((line = file.ReadLine()) != null)
{
    try
    {
        SqlCommand command = new SqlCommand(line, connection);
        command.ExecuteNonQuery();
    }
    catch (Exception ex)
    {
        LogErrorSomewhere(ex.Message, line);
    }
}

file.Close();

P.S. If you know, how to execute a such script using standard SQL tools, then you are welcome to leave me a comment.

Building OpenSSL with Visual Studio 2010 for x64 / Win64 causes error

visual-studio-2010-x64-cross-tools-command-prompt

Today I was trying to build the latest OpenSSL 1.0.1c with Visual Studio 2010. Following instructions form the INSTALL.W32, I was able to successfully build the 32-bit version. Trying the same with 64-bit (x64) version, again following the official instructions from INSTALL.W64.
To build for Win64/x64:
> perl Configure VC-WIN64A
> ms\do_win64a
> nmake -f ms\ntdll.mak
> cd out32dll
> ..\ms\test

The first line ‘perl Configure VC-WIN64A’ went without any errors:
Configuring for VC-WIN64A
no-ec_nistp_64_gcc_128 [default] OPENSSL_NO_EC_NISTP_64_GCC_128 (skip dir)
no-gmp [default] OPENSSL_NO_GMP (skip dir)
no-jpake [experimental] OPENSSL_NO_JPAKE (skip dir)
no-krb5 [krb5-flavor not specified] OPENSSL_NO_KRB5
no-md2 [default] OPENSSL_NO_MD2 (skip dir)
no-rc5 [default] OPENSSL_NO_RC5 (skip dir)
no-rfc3779 [default] OPENSSL_NO_RFC3779 (skip dir)
no-sctp [default] OPENSSL_NO_SCTP (skip dir)
no-shared [default]
no-store [experimental] OPENSSL_NO_STORE (skip dir)
no-zlib [default]
no-zlib-dynamic [default]
...
...
...
SIXTY_FOUR_BIT mode
DES_INT used
RC4_CHUNK is unsigned long long
Configured for VC-WIN64A.

The second line ‘ms\do_win64a’ always returned errors:
ml64 -c -Foms\uptable.obj ms\uptable.asm
Microsoft (R) Macro Assembler (x64) Version 10.00.40219.01
Copyright (C) Microsoft Corporation. All rights reserved.

Assembling: ms\uptable.asm
ms\uptable.asm(356) : error A2088:END directive required at end of file
ms\uptable.asm(356) : fatal error A1010:unmatched block nesting : _lazy18

Luckily I found solution in cyber-lynx.livejournal.com
Translation from Russian:
To prevent this, need to change file ms\do_win64a.bat like this: instead of

perl ms\uplink-x86_64.pl masm > ms\uptable.asm
ml64 -c -Foms\uptable.obj ms\uptable.asm

write

perl ms\uplink-x86_64.pl masm > ms\uptable.asm
ping 127.0.0.1
ml64 -c -Foms\uptable.obj ms\uptable.asm

It seems like race condition to me. Command ‘ping 127.0.0.1’ just adds a pause between two commands.

Thanks to Белая рысь (cyber_lynx)! Source: http://cyber-lynx.livejournal.com/40001.html

Did you know that IP addresses (IPv4) can be written in shorter representations?

Did you know that IPv4 addresses can be written in shorter representations, like IPv6 addresses?

Everyone have seen form of IPv6 represented as “shorter form”:
Example from IPv6:

  • 2001::7334
  • ::1
  • ::

You can use our free tool ipv6-literal.com to convert these addresses to long form. The result is:

  • 2001:0000:0000:0000:0000:0000:0000:7334
  • 0000:0000:0000:0000:0000:0000:0000:0001
  • 0000:0000:0000:0000:0000:0000:0000:0000

What admins / programmers usually do not know, is that the same principle applies to IPv4 addresses:

  • 127.1
  • 1
  • 192.168.257
  • 192.168.65535
  • 192.168.65535
  • 192.168
  • 10.1

To test these, use built in ping command. I used ping in Windows 7 and Ubuntu 10, and the result addresses are:

  • 127.1 -> 127.0.0.1
  • 1 -> 0.0.0.1
  • 192.168.257 -> 192.168.1.1
  • 192.168.65535 -> 192.168.255.255
  • 192.168 -> 192.0.0.168
  • 10.1 -> 10.0.0.1

As a bonus, you can try to ping other IP address representations:

  • ping 0x7F000001 – hex
  • ping 010 – octal, does not work in Ubuntu
  • ping 2130706433 – decimal

Why it works this way? Because network funcions built into OS support a such behavior, for example:

Have a fun, and remember, that year of IPv6 is near.