Blog

  • User & Schema Issues on SQL Server 2005

    Basically, this is due to the new schema / user separation in SQL Server 2005.  By default any users created in SQL Server 2005 will have a default schema of dbo, however for those users that were already part of the restored database, SQL Server 2005 has created a default schema of the same name as the user.  This causes a problem when attempting to delete the users as the drop user procedure (mysp_dropuser) will not drop the schema and a user cannot be dropped if it owns a schema.

    As a solution to this I would like modify the default schemas of all OurProduct® users to dbo.  I would then like to drop those schemas that were automatically created for the existing OurProduct® users.  This will ensure that OurProduct® users do not own schemas.  Therefore, preventing any errors on attempting to delete users in OurProduct®.

    To change the default schema of a user you need to run the following SQL:

    ALTER USER [user] WITH DEFAULT_SCHEMA = [new schema]

    e.g.

    ALTER USER myUser WITH DEFAULT_SCHEMA = dbo

    In order to create the SQL required to do this for all users could you run the following SQL and output the result to text.  You can then run the SQL that is output:

    SELECT 'ALTER USER '+ user_id + ' WITH DEFAULT_SCHEMA = dbo'
    FROM staff s
    JOIN sys.sysusers su
    ON su.name = s.user_id
    WHERE s.is_Deleted = 'N'

    The next part is then to drop those redundant schemas.  The SQL required for this would be as follows:

    DROP SCHEMA [schema]

    e.g.

    DROP SCHEMA myUser

    Again, in order to create the SQL required to do this for all users could you run the following SQL and output the result to text.  You can then run the SQL that is output:

    SELECT 'DROP SCHEMA '+ user_id
    FROM staff s
    JOIN sys.schemas su
    ON su.name = s.user_id
    WHERE s.is_Deleted = 'N'

    One further step that may be required is to re-associate any existing users with the new logins.  To do this, you just need to run the following SQL:

    EXEC sp_change_users_login 'Auto_Fix', '[user]'

    e.g.

    EXEC sp_change_users_login 'Auto_Fix', 'myUser'

    Again, just to generate the SQL required to do this for all users could you run the following SQL and output the result to text.  You can then run the SQL that is output:

    SELECT 'EXEC sp_change_users_login ''Auto_Fix'', '''+ user_id + ''''
    FROM staff s
    JOIN sys.sysusers su
    ON su.name = s.user_id
    WHERE s.is_Deleted = 'N'
  • Compiler Error Message: BC30456: ‘InitializeCulture’ is not a member of ‘ASP.default_aspx’.

    Compiler Error Message: BC30456: ‘InitializeCulture’ is not a member of ‘ASP.xxxx_aspx’.

    Solution: Turn off the option to “Allow this precompiled site to be updateable” when publishing

  • Convert a FAT32 file system to NTFS

    Go to All Programs (from Start), Accessories and Command Prompt.  Type;

    convert C:/fs:ntfs

    in Command Prompt to convert your C Drive. You can do the same for D drive with:

    convert D:/fs:ntfs

  • Updating a dataset in Crystal Reports

    To update a dataset in CR, without losing all the fields on the report do the following:

    • Open the Field Explorer
    • Expand Database Fields
    • Right click the dataset and choose Set Datasource Location…
    • Create New Connection
    • ADO.NET
    • Make New Connection
    • Browse for updated XSD (Class Name and Use Dataset from Class not required).
    • Click Finish
    • Select the same level items in both the Current Data Source and Replace With trees and click Update

    Review the database fields to ensure that the correct values have been passed through.

  • VSS Unspecified Error

    VSS throws up:

    Error: Unspecified error
    File: vsee\pkgs\vssprovider\cmsscciabstractionlayer.cpp
    Line number: 5906

    when it gets confused about the position of projects. Fix:

    • Close the solution and VS.Net
    • Backup solution folder
    • Delete solution folder
    • Delete IIS entries
    • Restart IIS
    • Get latest version from VSS
    • Open solution from SourceSafe location

    This should now work OK.

  • Crystal Report Timeout v10

    Crystal reports (CR) is timing out with v10. This can be fixed by applying the following change to web.config:

    
    
  • Compile and execute code on the fly…

    A simple way to compile and execute code on the fly. From the cmd console:

    notepad code.vb

    This opens notepad with a new file called code.vb

    Paste in a piece of code, for example:

    Imports SystemImports
    System.TextImports
    System.SecurityImports
    System.Security.CryptographyModule
    App
    Sub Main(ByVal argv() As String)

    Dim len As Integer = 128

    If argv.Length > 0 Then
    len = Integer.Parse(argv(0))
    End If

    Dim buff(len / 2) As Byte
    Dim rng As New RNGCryptoServiceProvider()

    rng.GetBytes(buff)

    Dim sb As New StringBuilder(len)
    Dim i As Integer

    For i = 0 To buff.Length - 1
    sb.Append(String.Format("{0:X2}", buff(i)))
    Next i

    Console.WriteLine(sb)
    Console.ReadLine()

    End Sub 'MainEnd Module

    Then save and close notepad.

    Compile the code:

    vbc code.vb

    Execute the code:

    code 128
    code 64

    Voila!!

  • ASP.NET 2.0 Machine Key

    When moving a fiddler based web test to a remote machine a Viewstate Mac error was received.

    This was caused because the viewstate is encoded using a MachineKey which is unique to the machine that the request was formulated on. So when the viewstate is read by the remote machine this throws an error.

    This can be overcome by adding a hardcoded machineKey to the web.config file as detailed in the following article.

    http://msdn.microsoft.com/library/default.asp?url=/library/en-us/dnpag2/html/PAGHT000007.asp