Archive for the 'Coding' Category

The database principal owns a schema in the database, and cannot be dropped

To delete the user go to Sql Server Management Studio, expand your database -> Security and select Schemas. In the Object Explorer Details (if not visible go to the View Menu select Object Explorer Details) you can see a list of the schemas and the owners.

Now locate the schema(s) of the user you want to delete, right click and select properties. In General you can see the schema owner, change it to the new owner (dbo for example).

When the user you want to delete has no schemas, you can delete it.

Saving changes is not permitted – Sql Server 2005

When adding an identity column to a table, I would sometimes get the following error:

“Saving changes is not permitted. The changes you have made require the following tables to be dropped and re-created. You have either made changes to a table that can’t be re-created or enabled the option Prevent saving changes that require the table to be re-created.”

In order to prevent this warning from occurring, Go to Tools > Options > Designers > Table and Database Designers > Uncheck the checkbox ‘Prevent saving changes that require the table to be re-created check box’

Screenshots

“Page cannot be found” when browsing aspx in IIS 6

In Windows 2003, all webservice extensions are “Prohibited” by default.

You need to enable ASP .net extensions to resolve the issue:

1. Open up IIS manager or, from your Run command, type inetmgr and press enter.
2. Expand the appropriate nodes in the IIS to locate the “Webservice Extensions” Node
3. Click on the same.
4. You will find a list of “prohibited” extensions in the right.
5. Click on ASP.NET and “allow” it

The task “Script Task” cannot run on this edition of Integration Services.

I was automating SSIS packages through .Net and would get this error when trying to run some packages when shelling out to dtexec.

The task “Script Task” cannot run on this edition of Integration Services. It requires a higher level edition.

It turns out that you need to have SSIS installed on the machine where you are running the app, as dtexec is not a client tool, like dts was.

Detailed explanation

IE6 does not support position:fixed

There are some script workarounds that might resolve IE6 not rendering position:fixed, but I just changed to position:absolute.

SSIS: Change an existing log file through dtexec

SSIS: Change an existing log file through dtexec

dtexec
/f “C:\Share.dtsx”
/l “DTS.LogProviderXMLFile;log.xml”
/Set “\package.Connections[log.xml].Properties[ConnectionString];C:\log2.xml”

Note: The log file (i.e. log.xml) must already be configured in the package

For Sql 2008, you need to add “.1” to the log provider type – DTS.LogProviderXMLFile.1

Disable Javascript in IE7

The only time I could see needing to do this is when you are testing if users have js enabled.

To disable Javascript in IE7

1. Tools / Internet Options / Security

2. Click Custom Level

3. In the Scripting section – click Disable for Active Scripting.

4. Close and restart your browser.

Change XP Login screen

By default Windows XP displays the Graphic login screen with icons and usernames at startup.

If you would like to use the more traditional Windows NT login screen you can get to that screen by pressing Ctrl Alt Del (Reboot key sequence) twice.

If you would like to change to the traditional screen at login, instead of the graphic login screen, do the following:

1. Log in with administrator access.
2. Click on Start, Control Panel, and select user accounts.
3. Click on Change the Way Users Log On or Off.
4. Click on the Box “Use the Welcome Screen” so that there is not check mark.

If you would like to switch from the traditional login screen to the more graphic screen just click on the box in step 4 above so the “Use the Welcome Screen” box is checked.

change all tables to dbo owner

Here is a sql server script I found that will change all tables to the dbo owner.

sp_MSforeachtable @command1=”EXEC sp_changeobjectowner ‘?’,’dbo'”

Open DBDiff

If you are developing on multiple servers, this app can help propagate object changes.

Open DBDiff is an open source database schema comparison tool for SQL Server 2005. It reports differences between two database schemas and provides a synchronization script to upgrade a database from one to the other.

Download

Maintenance Clean-up task not deleting files

I configured a Sql 2005 Maintenance clean-up task to delete all .bak files older than five days, but the historical backups were never deleted.

The only way I could get the clean-up task to function was to change the .bak extension to *.*. Now, all files older than five days are removed. Go figure.

Open folders in Windows Explorer mode by default (i.e. with folder pane enabled)

Open folders in Windows Explorer mode by default (i.e. with folder pane enabled)

When you double-click a folder, it opens the folder Window without the Explorer bar enabled (default setting). When you right-click on the folder and choose Explore, it does. To set Explore as the default action, follow these steps:

* Open My Computer window.
* Click Tools, Folder Options, then click File Types.
* From the list, locate the entry FOLDER with extension of (NONE).
* Click Advanced, select Explore, then Set Default
* Click OK and close the dialog.

Breakpoint in Application_Error

If you are trapping errors in the Application_Error event, you need to change the VS 2008 Debug settings to let the error pass through to the app event, rather than breaking at point in the code where the error occurred.

Under Options / Debugging / General – uncheck Enable Just My Code

Enter Null value in Management Studio

To enter a NULL value into a table through Management Studio, use ctrl+0 (zero)

return output value from dynamic sql

I was looking for a way to return an Identity value from a dynamic sql statement.

The simplest way is to pass an output parameter along with the sql:

Dim arrParams(0) As SqlParameter
arrParams(0) = New SqlParameter("@iSCID", SqlDbType.Int)
arrParams(0).Direction = ParameterDirection.Output

Then add the following to the end of the sql statement: ” ; Set @iSCID = @@Identity ”

You can then reference the value in this manner (I use the SqlHelper class from MS):

SqlHelper.ExecuteNonQuery(cn, CommandType.Text, strSql, arrParams)
iSCID = arrParams(0).Value

This page has a lot of great information.

The Curse and Blessings of Dynamic SQL

UPDATE: I ran into a situation where I was using triggers for an audit log that caused the above method to return weird @@Identity values. Turns out, if your trigger inserts into another table, that @@Identity will be returned, not the @@Identity from the intended table.

Detailed info – Excerpt below

on the side note: you should NEVER be using @@IDENTITY to get the last inserted identity from a table. this has been shouted down from the havens numerous times. @@IDENTITY will return the last inserted identity from ANY table of TRIGGER within the transaction session. you MUST use SCOPE_IDENTITY(). even IDENT_CURRENT is dangerous from the BOL about the dangers of using anything but SCOPE_IDENTITY():

SCOPE_IDENTITY and @@IDENTITY will return last identity values generated in any table in the current session. However, SCOPE_IDENTITY returns values inserted only within the current scope; @@IDENTITY is not limited to a specific scope.

For example, you have two tables, T1 and T2, and an INSERT trigger defined on T1. When a row is inserted to T1, the trigger fires and inserts a row in T2. This scenario illustrates two scopes: the insert on T1, and the insert on T2 as a result of the trigger.

Assuming that both T1 and T2 have IDENTITY columns, @@IDENTITY and SCOPE_IDENTITY will return different values at the end of an INSERT statement on T1.

@@IDENTITY will return the last IDENTITY column value inserted across any scope in the current session, which is the value inserted in T2.

SCOPE_IDENTITY() will return the IDENTITY value inserted in T1, which was the last INSERT that occurred in the same scope. The SCOPE_IDENTITY() function will return the NULL value if the function is invoked before any insert statements into an identity column occur in the scope.

Sql Server 2005 data file won’t shrink

Usually, setting Recovery Model to Simple in Options is enough to get started in shrinking a Sql Server db.

However, you may also need to rebuild clustered indexes on large tables. This reorganizes the index and releases the space.

How to export Excel from AJAX in .Net

In order to use the standard response.write method of exporting to excel, you need to force AJAX to make a full postback. Otherwise, parsing errors occur.

To force a postback, assign a control to a trigger and put the export logic in the control click event or in the page.ispostback portion of page_load.

Trigger syntax:


</ContentTemplate>
<Triggers>
<asp:PostBackTrigger ControlID="btnGo" />
</Triggers>
</asp:UpdatePanel>

Authenticated users getting logged out randomly

I was having a problem on a shared server with authenticated users getting logged out every couple of minutes. Turned out to be a simple fix by configuring a static machinekey for the web.config. By default, the authentication key is autogenerated by IIS each time the asp .net process cycles, which can be often on a shared machine.

MS info on MachineKey

IE6 AJAX problem

I put together a fairly simple chunk of code to display a loading image while a chart was rendering. This used an updatepanel and timer. It ran fine with IE6/7 locally and IE7 remote. But IE6 would not display the image on the remote server. Just a blank page and then the chart.

I looked at a lot of different posts and finally came to the solution. It looks like AJAX will automatically compress output. IE7 can handle this, but IE6 can not. By disabling the default compression, the image now appears in IE6 on the remote server.


<system.web.extensions>
<scripting>
<scriptResourceHandler enableCompression="false" enableCaching="true"/>
</scripting>
</system.web.extensions>


A similar type of issue.

  1.  

‘is not a valid identifier’ for large dynamic sql statement

I was building a large, dynamic pivot table which was getting the above error.

The solution turned out to be simple, but a little bit irritating.

I was calling exec @sql, which resulted in the error.

Changing the above to exec(@sql) worked for sql statements greater than 500 characters.

« Previous PageNext Page »