Archive for category SQL Server

Searching Stored Procedures

Here is a quick and easy way to search of stored procedures, views, user functions from within a database:

 –Search ALL user functions, views, stored procs

USE [PortalData]

SELECT OBJECT_NAME([id]) FROM syscomments

WHERE [id] IN (SELECT [id] FROM sysobjects WHERE xtype IN (‘fn’, ‘P’, ‘v’, ‘TR’, ‘U’, ‘X’))

AND [text] LIKE ‘%TypeSearchStringHere%

Leave a comment

Deleting Content Types that are still in use

If you are like me, you tend to deal with strange development nuances in the SharePoint environment.  One of those nuances is trying to delete a content type that is in use.   When I’m developing a solution that requires the creation of content types within the feature, I typically create that content type through code.  That will work on the first deployment of the feature since it does not exist yet.  On subsequent deployments, you will get an error that either the content type is in use (if you are trying to delete it before adding) or the content type already exists.  One thing I do is disable the deletion/creation of the content type if I’m not making any changes to it on subsequent deployments.  That will save a bit of development time.  The second problem I get every so often is the “content type still in use” error when trying to delete a content type.  I find this to happen if I am careless with removing items from a list, especially workflow tasks that are associated with a content type. 

I found a decent SQL Script (below) on the interweb that displays all the instances of my content type in the SharePoint databases.  In some cases, this will tell me where the “remnant” of the content type is and I can remove it.  Other times, it will display something that I already removed and I’m stuck.  If that happens, I first blow away the list where the content type was associated.  If the list removal doesn’t work, I will delete the site collection and build a new one.  (That is a luxury of having my own development VM.) I found that course of action to be quicker than trying to go through the database structure to find where to delete all instances of that content type.

 

Code Snippet
  1. SET @ContentTypeName='My Conent Type'
  2. SELECT w.Title AS [Web Site], w.FullUrl AS [Web Url], al.tp_Title AS [List Title], ct2.* FROM ContentTypes ct1 JOIN ContentTypes ct2 ON LEFT(ct2.ContentTypeId, Len(ct1.ContentTypeId))=ct1.ContentTypeId LEFT OUTER JOIN dbo.ContentTypeUsage ctu ON LEFT(ctu.ContentTypeId, Len(ct2.ContentTypeId)) = ct2.ContentTypeId LEFT OUTER JOIN dbo.AllLists al ON ctu.ListId = al.tp_Id AND ctu.WebId=al.tp_WebId LEFT OUTER JOIN dbo.Webs w ON al.tp_WebId = w.Id WHERE ct1.ResourceDir=@ContentTypeName

Sources: 1

Leave a comment

SQL Server tips helpful when installing SharePoint 2010

Tip #1 – There are two easy ways to tell which build of SQL Server you are running:

  1.  
    1. In SQL Server Management Studio, right click on the Server connection and click on Properties:sql_server_properties
    2. Run this query: SELECT SERVERPROPERTY(‘productversion’), SERVERPROPERTY (‘productlevel’), SERVERPROPERTY (‘edition’)

Tip #2 – At the time of this posting, this link contains the patches for all SQL Server builds.  Found this very helpful when trying to get my SQL Server 2008 ready for SharePoint 2010, which required Cumulative Update 2 for SP1.

1 Comment

SharePoint Configuration Wizard failing with SQL Exception – A number of possible fixes

While installing and configuring SharePoint Server 2010 in a extranet QA environment, I encountered an exception when running the SharePoint Configuration Wizard, which generates the SharePoint Config database among other things.  A dialog displayed an error of type System.ArgumentNullException… Parameter name: errorData:

SP2010-0033

This wasn’t very helpful, so I checked the SharePoint Log files under the 14 hive.  Again, nothing interesting.  Finally checked the event log and found a SQL exception error was occurring with SharePoint Foundation.  The error text from the event log was as follows:

Unknown SQL Exception 53 occurred. Additional error information from SQL Server is included below.

A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: Named Pipes Provider, error: 40 – Could not open a connection to SQL Server)

It would appear that there was a problem connecting to the database server (SQL Server 2008 SP1) from the server that SharePoint was being installed.  Working with the Database and Networking administrator, we found a few things that were not quite up to snuff.  It would be nice to say that one or a combination of the fixes that we executed resulted in fixing this problem, but it is not that clear.  Safe to say none of these tasks listed below were detrimental to the systems or the network.  Here is a run down of those tasks that enabled the configuration wizard to work:

SP2010-0032

    1. Alias – We found that the SQL alias that was defined, which we use in place of the actual SQL server name, was not setup properly in the SQL Server settings.  Rather, it was completely missing.  We added that back.

    2. SID – Ran NewSID on the new SharePoint 2010 server as it was spun up using VMWare tools.

    3. DNS – The DNS servers assigned to the SharePoint Server 2010 were two domain controllers for the extranet domain. The two DC’s did not have access to the internet and thus could not resolve DNS queries for external domains (i.e. www.microsoft.comwww.google.com, etc), which means any clients configured to use these servers for DNS resolution would also not be able to access the internet. For this reason, Windows update would not run on the SharePoint 2010 server, against the Microsoft update servers on the internet. The DNS configuration on the SharePoint server was temporarily changed to point to a DNS server which was able to resolve external domains, and Windows updates were run.  But we had forgotten to change the DNS configuration back to the original DC. This resulted in the SharePoint 2010 server not authenticating to the domain. Additionally, in this configuration, the server would not have been able to resolve the FQDN of the SQL server.

    4. Time – The local time on the database server was off, because it wasn’t authenticating to the extranet domain properly and getting it’s time set by the domain controller.

    5. FQDN Server Name – We were entering the database server name in the Wizard without the fully qualified domain name.  We added the “.domain.com” to the server name, ran the SharePoint Configuration Wizard and were able to make a connection to the database server, create the databases and complete the configuration.

    Shout out to Chris Ryan for his assistance getting this resolved!

     

1 Comment

Running SQL Management Studio as alternate user

At times, you may want to run SQL Server Management Studio as a different user than the AD account that you are logged into Windows.  This command run from the command line will let you do just that (your path to the location of ssms.exe may be different). Change the domain\admin_user to the user you’d like to “run as”:

runas /noprofile /netonly /user:domain\admin_user “C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE\ssms.exe”

Note! If you are running this command locally, leave off the “/netonly” property – Thanks DCON!

4 Comments