Archive for the 'Database / Sql' Category

How to add locations to Open File dialog in SSMS

Add subkeys Place0,Place1,etc

Under each subkey add two REG_SZ values

Name = “Shortcut Name”
Path = “Folder location”

HKEY_CURRENT_USER\Software\Microsoft\Microsoft SQL Server\100\Tools\Shell\Open Find\Places\UserDefinedPlaces

sp_configure and Ole Automation Procedures

I needed to allow access to file create and delete to a specific user in sql server 2008. This advanced option is now disabled by default.

To enable:

sp_configure ’show advanced options’, 1;
GO
RECONFIGURE;
GO
sp_configure ‘Ole Automation Procedures’, 1;
GO
RECONFIGURE;
GO

MySql with .Net SqlDataSource on hosted server

I was getting an error saying the .Net provider could not be found when attempting to connect to a MySql db in hosted environment. If the MySql.Data.MySqlClient is not loaded in the GAC on the hosted server, you will need to add a reference in your web.config, if you want to use the SqlDataSource control.

  1.  
  2. web.config - make sure the version matches your MySqlClient version
  3.  
  4. <system.data>
  5. <DbProviderFactories>
  6. <add name="MySQL Data Provider" invariant="MySql.Data.MySqlClient" description=".Net Framework Data Provider for MySQL" type="MySql.Data.MySqlClient.MySqlClientFactory, MySql.Data, Version=5.2.7.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d" />
  7. </DbProviderFactories>
  8. </system.data>
  9.  
  10. SqlDataSource reference
  11.  
  12. <asp:SqlDataSource ProviderName="MySql.Data.MySqlClient" ID="dsData" runat="server" ></asp:SqlDataSource>
  13.  

Change column order in MySql

Too bad the MySql GUI can’t handle this, but it is what it is:

ALTER TABLE `clientpackage` MODIFY COLUMN `ParentPackageId` mediumint AFTER `PackageId`

MySql import with crlf

If your text file lines end with carriage return / line feed, you will need \r in addition to \n to have clean data import:


LOAD DATA LOCAL INFILE 'c:\\www\\package.txt'
INTO TABLE businesscategory
LINES TERMINATED BY '\r\n'
(businesscategory);

YYYYMMDD for derived column in SSIS

I think SSIS is great, but date formatting still remains a bit tricky. Would be nice to have a straight format function, but this is what I needed to use in the expression portion of the Derived Column Transformation Editor in order to get the date format YearMonthDay :

(DT_STR,4,1252) DatePart("yyyy",Trans_Dttm) +
Right("0" + (DT_STR,4,1252) DatePart("m",Trans_Dttm),2) +
Right("0" + (DT_STR,4,1252) DatePart("d",Trans_Dttm),2)

SSMS 2008 stops showing 2005 dbs

I started getting this error out of the blue when trying to access a hosted 2005 db through SSMS 2008.

The server principal “db1″ is not able to access the database “db2″ under the current security context. (Microsoft SQL Server, Error: 916)

No databases would display under the databases tab and every refresh would result in the same error. I could see the dbs in SSMS 2005.

The fix is pretty weird. Click on the Databases folder, then View / Object Explorer Details. Then right click in the column headings and un-select Collation. Refresh the folder and the dbs should be there.

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

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

Next Page »