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,860 other subscribers

Archive for the ‘SQL Server’ Category

I was baffled…

Posted by jpluimers on 2011/11/15

When I saw code like this in a production app, I was speachless:

			if (matcher.Trim().Length > 0)
			{
				if (eesteWhere){sqlWhere += "WHERE ";eesteWhere = false;}
				else{sqlWhere += "AND ";}
				sqlWhere += "m.matcher like '" + matcher.Trim() + "%' ";
			}

Not once, twice, but hundred of fragments like these. Not generated, but hand copy-pasted. And the client thought they were running stable, reliable apps :(

This is soo XSCD ‘Exploits of a Mom‘ (aka Bobby Tables):

The department that wrote the code has been closed a while ago, but some serious refactoring time needs to be invested here, as all applications delivered by that department are vulnerable to SQL Exploits.

–jeroen

Posted in .NET, C#, C# 2.0, Database Development, Development, Software Development, SQL, SQL Server | Leave a Comment »

How do you add an administrator user to SQL Server 2008 (via Server Faultl)

Posted by jpluimers on 2011/05/18

When you (or the one that installed SQL Server 2008) forgot to add an administrator, it is still possible to add one.

The How do you add an administrator user to SQL Server 2008 question on Server Fault pointed me to the right page SQL Server 2008: Forgot to add an Administrator account? by Chris Randall.

Note that you might want to run SQL Server in Single User Mode; the first answer on the above question doesn’t mention that, but the second does (and pointed me to Chris Randall’s page).

–jeroen

via: How do you add an administrator user to SQL Server 2008? – Server Fault.

Posted in Database Development, Development, SQL Server | Leave a Comment »

Don’t sleep when you use your Entity Framework model from a separate assembly

Posted by jpluimers on 2011/05/05

The Entity Framework needs you to have a connection string in your App.Config.

It is good practice having your Entity Framework model in a separate assembly.

When using it in your main app, be aware that the connection string that belongs to your model needs to be in the App.config of your main app.

If not, you get an exception like this:

System.ArgumentException was unhandled
Message=The specified named connection is either not found in the configuration, not intended to be used with the EntityClient provider, or not valid.
Source=System.Data.Entity
StackTrace:
at System.Data.EntityClient.EntityConnection.ChangeConnectionString(String newConnectionString)
at System.Data.EntityClient.EntityConnection..ctor(String connectionString)
at System.Data.Objects.ObjectContext.CreateEntityConnection(String connectionString)
at System.Data.Objects.ObjectContext..ctor(String connectionString, String defaultContainerName)

The clue is the contents of the defaultContainerName parameter: you will see that in the App.config of your Entity Framework assembly.

Copy that over to the App.config of your main assembly, then make sure it points to your right database (if you use OTAP), then go :-)

Your App.config then looks like this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <connectionStrings>
    <add name="MyEntities" connectionString="metadata=res://*/My_EntityModel.csdl|res://*/My_EntityModel.ssdl|res://*/My_EntityModel.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=my-sql-server;initial catalog=my-database;persist security info=True;user id=my-user;password=my-password;multipleactiveresultsets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />
  </connectionStrings>
</configuration>

–jeroen

Posted in .NET, C#, Database Development, Development, EF Entity Framework, Software Development, SQL Server | Leave a Comment »

How to: Configure Express to accept remote connections – SQL Server Express WebLog – Site Home – MSDN Blogs

Posted by jpluimers on 2011/04/28

when developing embedded Windows software, SQL Express can be a good option.

However, embedded usually means you can’t install a big tool-set (like SQL Server Management Studio or SQL Server Profiler) on the target system.

So if you want to monitor or profile it, you need remote access to your SQL Express instance (usually SQLEXPRESS).

The How to: Configure Express to accept remote connections – SQL Server Express WebLog article on the SQL Server Express WebLog and the KB article How to configure SQL Server 2005 to allow remote connections explain the details.

This is a short summary:

  1. Enable TCP/IP using the SQL Server Configuration Manager
    (you can do this using the registry too)
  2. Enable the SQL Browser using the SQL Server Configuration Manager
  3. Open your firewall for the TCP ports (more difficult) or SQL Server process (easier)
  4. Enable mixed mode login authentication from the registry:
    HKLM/Software/Microsoft/MSSQLServer/MSSQLServer/LoginMode = 1 integrated security, 2 mixed.
  5. Make sure that SA can login, and give it a strong password using this in SQLCMD:
    ALTER LOGIN sa ENABLE
    ALTER LOGIN sa WITH PASSWORD=’Som3StrongP@assword’
  6. Restart the SQL Server Service
  7. Start the SQL Browser Service

Finally connect to your SQL Express server by using SQLCMD:

SQLCMD –S machinename\SQLEXPRESS –Usa –PSom3StrongP@assword

–jeroen

Posted in Database Development, Development, SQL Server | Leave a Comment »

Convert Microsoft Access JET SQL to SQL Server T-SQL Cheatsheet and Access JOIN parenthesis

Posted by jpluimers on 2011/03/14

There are truckloads of differences in SQL between Microsoft Access and SQL Server.

This Convert Microsoft Access JET SQL to SQL Server T-SQL Cheatsheet helps you convert between the two.

It doesn’t cover the parenthesis thing that Access needs on joins, but you can read on that here, here and here.

–jeroen

Posted in Access, Database Development, Development, SQL, SQL Server | Leave a Comment »

Stack Overflow ebooks

Posted by jpluimers on 2011/02/10

Greg Hewgill published a bunch Stack Overflow ebooks and StackExchange stats.
His readme explains a bit more on the books.
The blog he maintains makes up for some nice reading too.
Be sure to read the blog entry on the ebooks.

–jeroen

via Stack Overflow ebooks.

Posted in *nix, .NET, ASP.NET, C#, C# 2.0, C# 3.0, C# 4.0, Database Development, Delphi, Delphi for PHP, Development, HTML, HTML5, Java, Pingback, Power User, RegEx, Scripting, SocialMedia, Software Development, SQL, SQL Server, Stackoverflow, XML/XSD | Leave a Comment »

SQL Server: some date calculation logic

Posted by jpluimers on 2010/10/28

I always forget the syntax, because different DBMS systems use different ways of doing this.

This is the SQL Server way of doing some date calculations: Read the rest of this entry »

Posted in Database Development, Development, SQL Server | Leave a Comment »

SQL Server: obtain ServerProperty values using sqlcmd

Posted by jpluimers on 2010/10/20

When running different SQL server versions and editions, you often want to know what a certain instance is about.
For that, SQL Server T-SQL provides [WayBackServerProperty.

Since I absolutely love [WayBacksqlcmd, I extended my set of SQL Server batch files with this one showing you some of the [WayBack] ServerProperty values: Read the rest of this entry »

Posted in Database Development, Development, SQL Server | Leave a Comment »

Solution for OLE DB provider connecting to SQL Server giving error “Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done”

Posted by jpluimers on 2010/10/19

Recently, I had the error message “Multiple-step OLE DB operation generated errors. Check each OLE DB status value, if available. No work was done” occur to me when connecting through the “Microsoft OLE DB Provider for SQL Server”.

I got the below message (in this case in Delphi, but I have seen lots of other people having the same issue using other environments too): Read the rest of this entry »

Posted in Database Development, Delphi, Development, Software Development, SQL Server | 5 Comments »

SQL Server 2008: restoring backup of previous SQL Server version

Posted by jpluimers on 2010/09/21

When restoring a backup made in SQL Server 2005 to a SQL Server 2008 environment, you don’t see the underlying upgrade of the on-disk physical version in the UI (you only see the percentage completion moving from 0% to 100%).

When performing the same on the command-line you can actually follow the physical version gets updated:

C:\SCRIPT>"%sqlcmd%" -S . -E -Q "RESTORE DATABASE [MyDBA] FROM DISK = N'C:\BACKUP\MyDB.bak' WITH REPLACE, STATS = 10, MOVE N'MyDB' to N'C:\DATA\MyDB.mdf', MOVE N'MyDB_log' to N'C:\DATA\MyDB_log.ldf' ;"
19 percent processed.
29 percent processed.
39 percent processed.
49 percent processed.
59 percent processed.
69 percent processed.
78 percent processed.
88 percent processed.
98 percent processed.
100 percent processed.
Processed 1296 pages for database 'MyDBA', file 'MyDB' on file 1.
Processed 2 pages for database 'MyDBA', file 'MyDB_log' on file 1.
Converting database 'MyDBA' from version 611 to the current version 655.
Database 'MyDBA' running the upgrade step from version 611 to version 621.
Database 'MyDBA' running the upgrade step from version 621 to version 622.
Database 'MyDBA' running the upgrade step from version 622 to version 625.
Database 'MyDBA' running the upgrade step from version 625 to version 626.
Database 'MyDBA' running the upgrade step from version 626 to version 627.
Database 'MyDBA' running the upgrade step from version 627 to version 628.
Database 'MyDBA' running the upgrade step from version 628 to version 629.
Database 'MyDBA' running the upgrade step from version 629 to version 630.
Database 'MyDBA' running the upgrade step from version 630 to version 631.
Database 'MyDBA' running the upgrade step from version 631 to version 632.
Database 'MyDBA' running the upgrade step from version 632 to version 633.
Database 'MyDBA' running the upgrade step from version 633 to version 634.
Database 'MyDBA' running the upgrade step from version 634 to version 635.
Database 'MyDBA' running the upgrade step from version 635 to version 636.
Database 'MyDBA' running the upgrade step from version 636 to version 637.
Database 'MyDBA' running the upgrade step from version 637 to version 638.
Database 'MyDBA' running the upgrade step from version 638 to version 639.
Database 'MyDBA' running the upgrade step from version 639 to version 640.
Database 'MyDBA' running the upgrade step from version 640 to version 641.
Database 'MyDBA' running the upgrade step from version 641 to version 642.
Database 'MyDBA' running the upgrade step from version 642 to version 643.
Database 'MyDBA' running the upgrade step from version 643 to version 644.
Database 'MyDBA' running the upgrade step from version 644 to version 645.
Database 'MyDBA' running the upgrade step from version 645 to version 646.
Database 'MyDBA' running the upgrade step from version 646 to version 647.
Database 'MyDBA' running the upgrade step from version 647 to version 648.
Database 'MyDBA' running the upgrade step from version 648 to version 649.
Database 'MyDBA' running the upgrade step from version 649 to version 650.
Database 'MyDBA' running the upgrade step from version 650 to version 651.
Database 'MyDBA' running the upgrade step from version 651 to version 652.
Database 'MyDBA' running the upgrade step from version 652 to version 653.
Database 'MyDBA' running the upgrade step from version 653 to version 654.
Database 'MyDBA' running the upgrade step from version 654 to version 655.
RESTORE DATABASE successfully processed 1298 pages in 0.738 seconds (13.736 MB/sec).

Ain’t command-lines cool :-)

A few notes on version numbers:

655 – 2008
661 – 2008 R2

http://www.sqlskills.com/BLOGS/PAUL/post/Search-Engine-QA-13-Difference-between-database-version-and-database-compatibility-level.aspx
http://www.sqlskills.com/BLOGS/PAUL/post/SQL-Server-2008-R2-bumps-the-database-version.aspx
http://serverfault.com/questions/58039/sql-server-2008-2008r2-backup-compatibility
http://social.msdn.microsoft.com/Forums/en/sqldatabaseengine/thread/f8f8db38-3c20-45e4-ae8b-4cc097eb7f0d

–jeroen

Posted in CommandLine, Database Development, Development, Software Development, SQL Server | Leave a Comment »