The Wiert Corner – irregular stream of stuff

Jeroen W. Pluimers on .NET, C#, Delphi, databases, and personal interests

  • My badges

  • Twitter Updates

  • My Flickr Stream

  • Pages

  • All categories

  • Enter your email address to subscribe to this blog and receive notifications of new posts by email.

    Join 1,861 other subscribers

Archive for the ‘SQL Server 2008 R2’ Category

SQL Server 2012 is Generally Available! – SQL Server Team Blog – Site Home – TechNet Blogs

Posted by jpluimers on 2012/04/25

I’ve been really busy lately with a couple of migration projects, so I totally missed the various SQL Server 2012 is Generally Available! announcements.

Which is important because for one client, this opens the possibility of move from SQL Server 2000 right to SQL Server 2012  in stead of SQL Server 2008 R2 and make a more smooth path for Azure.

–jeroen

via:

Posted in Database Development, Development, SQL Server, SQL Server 2000, SQL Server 2008 R2, SQL Server 2012 | Leave a Comment »

SQL Server 2000 (and probably later) other reason for System.Data.SqlClient.SqlException: A severe error occurred on the current command. (via SQL Server Forums)

Posted by jpluimers on 2012/04/24

While transitioning from SQL Server 2000 to 2008, I recently had the “A severe error occurred on the current command. The results, if any, should be discarded.”  occurring on SQL Server 2000 in the form as shown at the bottom of this message.

Many of the search results point you into the area of atabase corruption, or in using NVARCAR parameters with SQL Server 2000 or SQL Server 2005 (the app didn’t use NVARCAR, nor did it use large VARCHAR parameters).

The cool thing on the SQL Server Forums – System.Data.SqlClient.SqlException: A severe error occurred on the current command post was that it summed up causes, and asked for more:

Posted – 06/17/2004 :  15:05:20

Rashid writes “Hi: Gurus I am getting these errors when I try to execute my application. According to MS knowledge base (http://support.microsoft.com/default.aspx?scid=kb;en-us;827366) these errors happen due to following resons

  1. You use a SqlClient class in a Finalize method or in a C# destructor.
  2. You do not specify an explicit SQLDbType enumeration when you create a SqlParameter object. When you do not specify an explicit SQLDbType, the Microsoft .NET Framework Data Provider for SQL Server (SqlClient) tries to select the correct SQLDbType based on the data that is passed. SqlClient is not successful.
  3. The size of the parameter that you explicitly specify in the .NET Framework code is more than the maximum size that you can use for the data type in Microsoft SQL Server.

None of these are true in my case. Are there any other reasons that can cause these problems..

There is one more: sending huge SQL Statements to your SQL Server is always a bad idea and gives this error too. Read the rest of this entry »

Posted in .NET, C#, C# 2.0, C# 3.0, C# 4.0, Database Development, Development, Encoding, Software Development, SQL Server, SQL Server 2000, SQL Server 2008 R2, Unicode | Leave a Comment »

Migrating SQL Server 2000 ISQLW Utility to SQL Server 2008 R2 SSMS command-line parameters (SQL Query Analyzer; SQL Server Management Studio)

Posted by jpluimers on 2012/04/17

If you followed my blog, you probably already guessed that I’m assisting a client to prepare for a big SQL Server 2000 to SQL Server 2008 R2 migration. When not, you know now :)

I’m a fan of commandline, tools, and preconfigured settings. Which means that I’m in the midst of reconfiguring all my shortcuts to SQL Server 2000 tools to SQL Server 2008 equivalents.

When inspecting and changing LNK shortcut files, two tools are important:

  • dumplnk: dumps a shortcut lnk file from the commandline
  • shurtcut: creates a shortcut lnk file from the commandline

One of tools I many shortcuts for is the ISQLW aka SQL Query Analyzer, which I use far more than the SQL Server Enterprise Manager (more on SSEM in a future post).

Depending on the mode of authentication you use to connect to your SQL Server, there basically are two forms of shortcuts:

  • SQL Server Authentication (using SQL Server username and password):
    "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\isqlw.exe" /S"servername[\instancename]" /U"username" /P"password"
  • Windows Authentication (using the credentials of the currently logged in windows user):
    "C:\Program Files\Microsoft SQL Server\80\Tools\Binn\isqlw.exe" /S"servername[\instancename]" /E

The former is less secure (so better to only store those shortcuts in a place that no other users can access).

From the ISQLW.exe syntax documentation:

Syntax

isqlw
[-?] |
[
[-S server_name[\instance_name]]
[-d database]
[-E] [-U user] [-P password]
[{-i input_file} {-o output_file} [-F {U|A|O}]]
[-f file_list]
[-C configuration_file]
[-D scripts_directory]
[-T template_directory]
]

The parameters /S, /U, /P and /E are very similar to the -S, -U, -P and -E ones from SSMS.exe (SQL Server Management Studio) with one distinction: there MUST be a space between each parameter and the value:

  • SQL Server Management Studio (using SQL Server username and password):
    "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" -S "servername[instancename]" -U "username" -P "password"
  • SQL ServerManagement Studio (using credentials for the currently logged in windows user):
    "C:\Program Files\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\Ssms.exe" -S "servername[instancename]" -E

Read the rest of this entry »

Posted in Batch-Files, Database Development, Development, Power User, Scripting, Software Development, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012 | 5 Comments »

Migrate/Transfer SQL Server 2008/2005/2000/7 Logins to SQL Server 2008

Posted by jpluimers on 2012/01/12

When moving databases across servers, you face the same problem as when upgrading servers: users are server specific, but permissions are databases specific. They are not bound by UserName, but through a SID (security identifier).

When adding the same UserName entries to a new server that already has the databases restored, you get error messages like these:

Error 21002 [SQL-DMO] User ‘account’ already exists

When adding the same UserName  entries, then restoring the databases, it won’t work, because the matching SIDs don’t exist.

There are many sites explaining the “Error 21002” and pointing to sp_change_users_login.

But sp_change_users_login (and the ALTER USER UserName WITH LOGINI = UserName2 in SQL Server 2005 and higher) is not the actual fix to the problem: it will re-add the user with a new SID, then correct the SID in the database currently in use.

Actually you are after “Orphaned” users: users that are defined in the various databases, but not present in the user list on the SQL Server instance. Running sp_change_users_login with the “Report’ parameter on the “new” server will show a list of orphaned users.

An even better way to show Orphaned Users is by running the ShowOrphanUsers script (thanks Vyas, wish more people republish your stuff with attribution!). In my own version (sourcecode is below), I have added an extra UserSID column of type varbinary(85).

In order to transfer users to a new server, you need a sp_help_revlogin stored procedure. Depending on the version of your SQL Server (7/2000/2005/2008), you need a slightly different version of a script that creates sp_help_revlogin for you. All versions are available at NetNerds.net.

–jeroen

via: Migrate/Transfer SQL Server 2008/2005/2000/7 Logins to SQL Server 2008.

USE master;
GO
IF OBJECT_ID ('dbo.ShowOrphanUsers') IS NOT NULL
  DROP PROCEDURE dbo.ShowOrphanUsers
GO
CREATE PROC dbo.ShowOrphanUsers
AS
BEGIN
	CREATE TABLE #Results
	(
		[Database Name] sysname COLLATE Latin1_General_CI_AS,
		[Orphaned User] sysname COLLATE Latin1_General_CI_AS,
                [UserSID]  varbinary(85)
	)

	SET NOCOUNT ON

	DECLARE @DBName sysname, @Qry nvarchar(4000)

	SET @Qry = ''
	SET @DBName = ''

	WHILE @DBName IS NOT NULL
	BEGIN
		SET @DBName =
				(
					SELECT MIN(name)
					FROM master..sysdatabases
					WHERE 	name NOT IN
						(
						 'master', 'model', 'tempdb', 'msdb',
						 'distribution', 'pubs', 'northwind'
						)
						AND DATABASEPROPERTY(name, 'IsOffline') = 0
						AND DATABASEPROPERTY(name, 'IsSuspect') = 0
						AND name > @DBName
				)

		IF @DBName IS NULL BREAK

		SET @Qry = '	SELECT ''' + @DBName + ''' AS [Database Name],
				CAST(name AS sysname) COLLATE Latin1_General_CI_AS  AS [Orphaned User],
                                SID AS [UserSID]
				FROM ' + QUOTENAME(@DBName) + '..sysusers su
				WHERE su.islogin = 1
				AND su.name <> ''guest''
				AND NOT EXISTS
				(
					SELECT 1
					FROM master..sysxlogins sl
					WHERE su.sid = sl.sid
				)'

		INSERT INTO #Results EXEC (@Qry)
	END

	SELECT *
	FROM #Results
	ORDER BY [Database Name], [Orphaned User]
END
GO

Posted in Database Development, Development, SQL, SQL Server, SQL Server 2000, SQL Server 2005, SQL Server 2008, SQL Server 2008 R2, SQL Server 2012, SQL Server 7 | 1 Comment »