TechEd Europe 2014

Leave a comment

I have been selected to staff at TechEd in Barcelona. So if you are there, go to the Data Platform Booth. That’s where I’ll be standing answering questions all day long. I’m also representing SQL Server at the “Ask the experts” session once again. That’ll be really exciting! Before that I hope to make it in time for the SQL Server Saturday that also is in Barcelona.

Did you attend any Microsoft class and need the lab files?

Leave a comment

Well, they are a bit difficult to get from the virtual machines, and almost impossible if you have been using LabsOnline.

Microsoft has compiled a page with a lot of lab files and setup scripts here:

https://www.microsoft.com/learning/en-us/companion-moc.aspx

I guess they are pretty useless without the lab instructions, but feel free to download them 🙂

And speaking of download… The SQL Server sample database location is still codeplex…

http://msftdbprodsamples.codeplex.com/

Happy sampling

Rebuild Master

2 Comments

The master.mdf is corrupt. The disk failed… Powerfailure? This never occurs at a convenient time. The ERRORLOG-file has a message similar to this.

Error 2(failed to retrieve text for this error. Reason: 15100) occurred while opening file
‘C:\Program Files\Microsoft SQL Server\MSSQL10.MSSQLSERVER\MSSQL\DATA\master.mdf’
to obtain configuration information at startup.

This is of course easily fixed. It’s only to resore the backup we have of all our system databases. Just one small problem… SQL Server doesn’t start.

Time to rebuild the system databases. But first : Documentation!

  1. Look for “Authentication mode is MIXED.” (or “Authentication mode is WINDOWS-ONLY.” ) Write it up.
  2. Document what Collation you want. If you want “same as before”, just forget it. Otherwise write the new Collation on the same piece of paper. (I’m documenting “Finnish_Swedish_CI_AS”)
  3. How do you connect to SQL Server? If you have a backslash somewhere in your servername, you have a named instance. (connecting to COMPUTER\FINANCE gives you the instancename FINANCE) However if you only use the servername, you probanly have a default instance, in which case the instancename is MSSQLSERVER – Onto the paper!

 

Command:

Same syntax since SQL Server 2008. Still works in SQL Server 2014 (CTP2) and has no signs that it would stop working:

Setup.exe /ACTION=REBUILDDATABASE
/INSTANCENAME=MSSQLSERVER  
/SQLSYSADMINACCOUNTS=win7x64pro\mikael 
/SAPWD=P@ssw0rd
/SQLCOLLATION=Finnish_Swedish_CI_AS

  • ACTION – obviously
  • INSTANCENAME – the instancename documented in item 3.
  • SQLSYSADMINACCOUNTS – Windows account(s) who will be sysadmin of the server.
  • SAPWD – This parameter MUST be present if item 1 states the server started with MIXED autentication.
  • SQLCOLLATION – from item 2.
  • QUIET – I recommend using this. Saves some clicking.

OK, now you’ll have to run this command in an elevated command prompt. That is the command prompt starting in C:\Windows\System32 instead of in your user profile. Then it’s only to navigate to the folder of “setup.exe” and run the command line. All words are typed on one line BEFORE hitting ENTER!

If your installation is made with C:\Program Files\ as the root, the setup.exe can be found here:

SQL 2008 – C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\Release\Setup.exe

SQL 2008 R2 – C:\Program Files\Microsoft SQL Server\100\Setup Bootstrap\SQLServer2008R2\Setup.exe
(I found another setup.exe in the same folder as for SQL 2008, but running that file generated errors instead of databases…)

SQL 2012 – C:\Program Files\Microsoft SQL Server\110\Setup Bootstrap\SQLServer2012\Setup.exe

SQL 2014 CTP2 – C:\Program Files\Microsoft SQL Server\120\Setup Bootstrap\SQL14CTP2\Setup.exe

and my guess is that RTM of SQL 2014 will use the same path as before:
C:\Program Files\Microsoft SQL Server\120\Setup Bootstrap\SQLServer2014\Setup.exe 
or potentially 
C:\Program Files\Microsoft SQL Server\120\Setup Bootstrap\SQL14\Setup.exe

 

For all Swedish speaking readers, please check out SQL Server pĂĄ svenska

ASYNC_NETWORK_IO for dummies

Leave a comment

I often come across “less than optimal” applications, when I do performance tuning. You know, that kind of application that are kind of responsive, but the main issue is the slowness. Everything about the application is sloooow…

What is one of the signs that you might have a slow client application? (Disclaimer: Slow = Doesn’t consume SQL Server data in zero or less milliseconds. All applications are more or less slow, but abnormal slowness can make users mad.)

The magical query:

SELECT *
FROM sys.dm_os_wait_stats
order by wait_time_ms desc

According to Guy Bowermans article, the statistics lifetime is (about) the time of the SQLTRACE_INCREMENTAL_FLUSH_SLEEP.

I now did some illustrative tests: I wrote an extremely simple console application, selecting the ID column from a table with ~1000000 rows.

Code: (C#, Console project)

static void Main(string[] args)
{

SqlConnection con = new SqlConnection(“Data Source=.;Initial Catalog=testdata;Integrated Security=SSPI;”);
SqlCommand cmd = new SqlCommand(“SELECT SalesOrderID FROM [Sales].[SalesOrderDetail]”, con);
SqlCommand cmdclearstat = new SqlCommand(“DBCC SQLPERF (‘sys.dm_os_wait_stats’, CLEAR);”, con);

con.Open();

cmdclearstat.ExecuteNonQuery();
SqlDataReader rdr = cmd.ExecuteReader();

while (rdr.Read())
{
int a = rdr.GetInt32(0);
//Console.WriteLine(rdr.GetInt32(0));
}

con.Close();

}

When I ran this code, the SQLTRACE_INCREMENTAL_FLUSH_SLEEP was 4000 at the time of the application end. The ASYNC_NETWORK_IO was at 122, giving us a wait ratio of 0.03.

The “problem” resulting in the real issue is: My application takes 4 seconds to run – without any feedback to the user. Not many users are comfortable with that. The “solution” is to uncomment the Console.Writeline() line. (I actually also removed the int a… line, in order to reading the same amount of objects.)

Results was amazing! I could follow the progress of the application as it looped through my rows. When the application was ready, the SQLTRACE_INCREMENTAL_FLUSH_SLEEP had reached 120024! Yes that’s correct! Two minutes of wonderful interaction 🙂 And the ASYNC_NETWORK_IO (the time SQL Server waited for my application to get the next row) was 120201. That is a ratio of  1.0015.

The server indicates that a “slow” application has made the server wait a lot! So what should you do?

Sometimes you have to choose between the unresponsiveness and the slowness, but sometimes you can get the best of the two worlds. You can try to update the screen every 10000 row, or even every 50000 row. Even with the code overhead, this application completed in virtually the same time as the blazing fast one. The difference was ASYNC_NETWORK_IO waited for 160 ms, resulting in a  0.04 ratio. Still acceptable, and the application (randomly) outputted data, making it seem more responsive.

“Optimal code fragment” replacing the while(rdr.Read()) statement:

int count = 0;
while (rdr.Read())
{
int a = rdr.GetInt32(0);
if (count % 50000 == 0)
{
Console.WriteLine(a);
}
count++;
}

Hopefully you’ll be able to identify some issues with these samples.