<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Shawson&#039;s Code Blog &#187; SQL Server</title>
	<atom:link href="http://codeblog.shawson.co.uk/category/sql-server/feed/" rel="self" type="application/rss+xml" />
	<link>http://codeblog.shawson.co.uk</link>
	<description>development notes for my failing memory</description>
	<lastBuildDate>Tue, 15 May 2012 15:22:30 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
		<item>
		<title>Open Windows Firewall ports for SQL Server 2008</title>
		<link>http://codeblog.shawson.co.uk/open-windows-firewall-ports-for-sql-server-2008/</link>
		<comments>http://codeblog.shawson.co.uk/open-windows-firewall-ports-for-sql-server-2008/#comments</comments>
		<pubDate>Fri, 04 Nov 2011 15:23:12 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[Batch Scripting]]></category>
		<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://codeblog.shawson.co.uk/?p=1274</guid>
		<description><![CDATA[http://support.microsoft.com/kb/968872 As noted in the article, you can run this batch file; @echo ========= SQL Server Ports =================== @echo Enabling SQLServer default instance port 1433 netsh firewall set portopening TCP 1433 "SQLServer" @echo Enabling Dedicated Admin Connection port 1434 netsh firewall set portopening TCP 1434 "SQL Admin Connection" @echo Enabling conventional SQL Server Service Broker [...]


Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/command-line-to-delete-every-file-older-than-30-days/' rel='bookmark' title='Command line to delete every file older than 30 days'>Command line to delete every file older than 30 days</a></li>
<li><a href='http://codeblog.shawson.co.uk/how-to-run-sql-profiler-against-local-sql-express-instances/' rel='bookmark' title='How to run SQL Profiler against local SQL Express instances'>How to run SQL Profiler against local SQL Express instances</a></li>
<li><a href='http://codeblog.shawson.co.uk/aspnet-role-membership-providers-under-iis7-doesnt-work/' rel='bookmark' title='ASP.Net Role &amp; Membership Providers (Under IIS7) &#8211; DOESN&#8217;T Work!'>ASP.Net Role &#038; Membership Providers (Under IIS7) &#8211; DOESN&#8217;T Work!</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p><a href="http://support.microsoft.com/kb/968872">http://support.microsoft.com/kb/968872</a></p>
<p>As noted in the article, you can run this batch file;</p>
<pre>
@echo =========  SQL Server Ports  ===================
@echo Enabling SQLServer default instance port 1433
netsh firewall set portopening TCP 1433 "SQLServer"
@echo Enabling Dedicated Admin Connection port 1434
netsh firewall set portopening TCP 1434 "SQL Admin Connection"
@echo Enabling conventional SQL Server Service Broker port 4022
netsh firewall set portopening TCP 4022 "SQL Service Broker"
@echo Enabling Transact-SQL Debugger/RPC port 135
netsh firewall set portopening TCP 135 "SQL Debugger/RPC"
@echo =========  Analysis Services Ports  ==============
@echo Enabling SSAS Default Instance port 2383
netsh firewall set portopening TCP 2383 "Analysis Services"
@echo Enabling SQL Server Browser Service port 2382
netsh firewall set portopening TCP 2382 "SQL Browser"
@echo =========  Misc Applications  ==============
@echo Enabling HTTP port 80
netsh firewall set portopening TCP 80 "HTTP"
@echo Enabling SSL port 443
netsh firewall set portopening TCP 443 "SSL"
@echo Enabling port for SQL Server Browser Service's 'Browse' Button
netsh firewall set portopening UDP 1434 "SQL Browser"
@echo Allowing multicast broadcast response on UDP (Browser Service Enumerations OK)
netsh firewall set multicastbroadcastresponse ENABLE
</pre>


<p>Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/command-line-to-delete-every-file-older-than-30-days/' rel='bookmark' title='Command line to delete every file older than 30 days'>Command line to delete every file older than 30 days</a></li>
<li><a href='http://codeblog.shawson.co.uk/how-to-run-sql-profiler-against-local-sql-express-instances/' rel='bookmark' title='How to run SQL Profiler against local SQL Express instances'>How to run SQL Profiler against local SQL Express instances</a></li>
<li><a href='http://codeblog.shawson.co.uk/aspnet-role-membership-providers-under-iis7-doesnt-work/' rel='bookmark' title='ASP.Net Role &amp; Membership Providers (Under IIS7) &#8211; DOESN&#8217;T Work!'>ASP.Net Role &#038; Membership Providers (Under IIS7) &#8211; DOESN&#8217;T Work!</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://codeblog.shawson.co.uk/open-windows-firewall-ports-for-sql-server-2008/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Executing sql statements from the command line (SQL Server 2008 R2 Express)</title>
		<link>http://codeblog.shawson.co.uk/executing-sql-statements-from-the-command-line-sql-server-2008-r2-express/</link>
		<comments>http://codeblog.shawson.co.uk/executing-sql-statements-from-the-command-line-sql-server-2008-r2-express/#comments</comments>
		<pubDate>Thu, 03 Nov 2011 09:46:16 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://codeblog.shawson.co.uk/?p=1269</guid>
		<description><![CDATA[One of the things I&#8217;ve always liked about MySql is its easy to use command line interface. Microsoft Enterprise Manager was always pretty good, and of course SQL Management Studio, so I rarly have to interface with MSSQL using the command line, but when I did, I always used osql. As of SQL 2008 this [...]


Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/cross-server-queries-in-sql-server/' rel='bookmark' title='Cross server queries in SQL Server'>Cross server queries in SQL Server</a></li>
<li><a href='http://codeblog.shawson.co.uk/setting-up-session-state-database-on-sql-server/' rel='bookmark' title='Setting up session state database on sql server'>Setting up session state database on sql server</a></li>
<li><a href='http://codeblog.shawson.co.uk/ssis-dts-packages-violating-referential-integrity/' rel='bookmark' title='SSIS / DTS packages violating referential integrity'>SSIS / DTS packages violating referential integrity</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>One of the things I&#8217;ve always liked about MySql is its easy to use command line interface.  Microsoft Enterprise Manager was always pretty good, and of course SQL Management Studio, so I rarly have to interface with MSSQL using the command line, but when I did, I always used osql.  As of SQL 2008 this was replaced by sqlcmd which is very similar to the mysql command line implementation.  Basic usage is;</p>
<pre class="brush: sql">
sqlcmd -S server_name\instance_name -U sa -P your_password
</pre>
<p>You can then type directly into the console, executing a &#8220;GO&#8221; after each statement to run.  I recently used this to enable remote connections on a new install of sql express, like so;</p>
<pre>
1> exec sys.sp_configure N'remote access', N'1'
2> GO
Configuration option 'remote access' changed from 0 to 1. Run the RECONFIGURE statement to install.
1> RECONFIGURE WITH OVERRIDE
2> GO
1> exit
</pre>


<p>Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/cross-server-queries-in-sql-server/' rel='bookmark' title='Cross server queries in SQL Server'>Cross server queries in SQL Server</a></li>
<li><a href='http://codeblog.shawson.co.uk/setting-up-session-state-database-on-sql-server/' rel='bookmark' title='Setting up session state database on sql server'>Setting up session state database on sql server</a></li>
<li><a href='http://codeblog.shawson.co.uk/ssis-dts-packages-violating-referential-integrity/' rel='bookmark' title='SSIS / DTS packages violating referential integrity'>SSIS / DTS packages violating referential integrity</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://codeblog.shawson.co.uk/executing-sql-statements-from-the-command-line-sql-server-2008-r2-express/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Wizard generated SSIS package dumps critical files in Temp folder- breaks after a log out!</title>
		<link>http://codeblog.shawson.co.uk/wizard-generated-ssis-package-dumps-critical-files-in-temp-folder-breaks-after-a-log-out/</link>
		<comments>http://codeblog.shawson.co.uk/wizard-generated-ssis-package-dumps-critical-files-in-temp-folder-breaks-after-a-log-out/#comments</comments>
		<pubDate>Fri, 05 Aug 2011 11:00:09 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://codeblog.shawson.co.uk/?p=1127</guid>
		<description><![CDATA[I&#8217;ve recently spent a day of so of my life doing something which I did in minutes using DTS (And I&#8217;m sure on SSIS in the past??). I selected export data from a database in sql 2005 and chose my destination database and a bunch of tables. At the end I select save as SSIS [...]


Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/sql-server-export-text-was-truncated-or-one-or-more-characters-had-no-match-in-the-target-code-page/' rel='bookmark' title='SQL Server Export : &#8220;Text was truncated or one or more characters had no match in the target code page&#8221;'>SQL Server Export : &#8220;Text was truncated or one or more characters had no match in the target code page&#8221;</a></li>
<li><a href='http://codeblog.shawson.co.uk/ssis-dts-packages-violating-referential-integrity/' rel='bookmark' title='SSIS / DTS packages violating referential integrity'>SSIS / DTS packages violating referential integrity</a></li>
<li><a href='http://codeblog.shawson.co.uk/how-to-run-sql-profiler-against-local-sql-express-instances/' rel='bookmark' title='How to run SQL Profiler against local SQL Express instances'>How to run SQL Profiler against local SQL Express instances</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve recently spent a day of so of my life doing something which I did in minutes using DTS (And I&#8217;m sure on SSIS in the past??).  I selected export data from a database in sql 2005 and chose my destination database and a bunch of tables.  At the end I select save as SSIS package; everything runs fine.</p>
<p>I can exit the sql management studio, run the package again&#8211; all ok.</p>
<p>I then log out, log back in, run the package, and I&#8217;m swamped with errors about missing tmp files.  </p>
<p>It turns out that the ssis wizard, dumps critical parts of the ssis package (table schema and the like) out into temp files (Only when you tick optimize for multiple tables- whcih I had to in order to be able to use transactions), which on our system gets wiped on logout- so when you come back, the package is crippled.  </p>
<p>I found a solution on <a href="http://www.bigresource.com/Tracker/Track-ms_sql-m6lqRcSd/">BigResource.com from user jaegd</a>;</p>
<blockquote><p>
The Import/Export wizard created files are stored in the TMP environment variable by default.</p>
<p>To store the Import Export Data wizard files with a checked &#8220;Optimize for many tables&#8221; setting in a particular directory, create a batch file with the following contents (change the dir name to one you want) and run it.</p>
<p>set TMP=c:\place_for_files<br />
dtswizard.exe</p>
<p>This approach just changes the TMP location temporarily to a place you&#8217;d prefer.</p>
<p>If you don&#8217;t want to create a batch file, just run the following from Start/Run&#8230;</p>
<p>cmd /c set TMP=c:\place_for_files &#038;&#038; dtswizard.exe
</p></blockquote>
<p>This has fixed it!  Such a relief- I set the env var tmp to c:\scripts\SSISFiles then generate the SSIS package, and save it to the file system in c:\scripts\ with no sensitive data embedded, then fire it off from the command line, supplying the connection strings.  </p>
<pre>
dtexec.exe /FILE "C:\scripts\MySSISPackage.dtsx" /CONNECTION DestinationConnection;"\"Data Source=SiteDB\SQLEXPRESS;User ID=sync-user;Password=abc123;Initial Catalog=Chinook;Provider=SQLNCLI;Auto Translate=false;\"" /CONNECTION SourceConnection;"\"Data Source=CentralSQL;User ID=sync-user;Password=abc123;Initial Catalog=ProductDataStore;Provider=SQLNCLI;Auto Translate=false;\"" /MAXCONCURRENT " -1 " /CHECKPOINTING OFF  /REPORTING V  /CONSOLELOG NCOSGXMT >Log.txt
</pre>
<p>This way everything is kept nicely grouped together.  Thought I would blog it for future me, and to prevent anyone else shaving 3 years off their life with stress.</p>


<p>Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/sql-server-export-text-was-truncated-or-one-or-more-characters-had-no-match-in-the-target-code-page/' rel='bookmark' title='SQL Server Export : &#8220;Text was truncated or one or more characters had no match in the target code page&#8221;'>SQL Server Export : &#8220;Text was truncated or one or more characters had no match in the target code page&#8221;</a></li>
<li><a href='http://codeblog.shawson.co.uk/ssis-dts-packages-violating-referential-integrity/' rel='bookmark' title='SSIS / DTS packages violating referential integrity'>SSIS / DTS packages violating referential integrity</a></li>
<li><a href='http://codeblog.shawson.co.uk/how-to-run-sql-profiler-against-local-sql-express-instances/' rel='bookmark' title='How to run SQL Profiler against local SQL Express instances'>How to run SQL Profiler against local SQL Express instances</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://codeblog.shawson.co.uk/wizard-generated-ssis-package-dumps-critical-files-in-temp-folder-breaks-after-a-log-out/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;</title>
		<link>http://codeblog.shawson.co.uk/entity-framework-the-data-reader-is-incompatible-with-the-specified-complex-type/</link>
		<comments>http://codeblog.shawson.co.uk/entity-framework-the-data-reader-is-incompatible-with-the-specified-complex-type/#comments</comments>
		<pubDate>Tue, 07 Jun 2011 16:07:21 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[C#.net]]></category>
		<category><![CDATA[Linq]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://codeblog.shawson.co.uk/?p=1024</guid>
		<description><![CDATA[I recently had this problem with a site I&#8217;m working on. I&#8217;m using Entity framework to access a bunch of legacy stored procedures, originally in MySQL but ported over to MSSQL. Having added the sprocs to EF and let it auto-generate it&#8217;s magic, I was shocked to find one of my calls throwing the following [...]


Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/cross-apply-in-sql/' rel='bookmark' title='Cross Apply in SQL'>Cross Apply in SQL</a></li>
<li><a href='http://codeblog.shawson.co.uk/entity-framework-4-1-code-first-with-one-to-many-relationship-code-example/' rel='bookmark' title='Entity Framework 4.1 Code First (With One to Many relationship) Code Example'>Entity Framework 4.1 Code First (With One to Many relationship) Code Example</a></li>
<li><a href='http://codeblog.shawson.co.uk/asp-net-build-step-to-minify-and-obfuscate-your-sites-javascript-and-css/' rel='bookmark' title='Adding minification and obfuscation of your Javascript and CSS to your ASP.net build process using Yahoo YUI Compressor'>Adding minification and obfuscation of your Javascript and CSS to your ASP.net build process using Yahoo YUI Compressor</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>I recently had this problem with a site I&#8217;m working on.  I&#8217;m using Entity framework to access a bunch of legacy stored procedures, originally in MySQL but ported over to MSSQL.  Having added the sprocs to EF and let it auto-generate it&#8217;s magic, I was shocked to find one of my calls throwing the following exception;</p>
<pre>
System.Data.EntityCommandExecutionException: The data reader is incompatible with the specified &amp;#39;ChinookModel.GetVehicleDescFromModelId_Result1&amp;#39;. A member of the type, &amp;#39;ivaluationid1&amp;#39;, does not have a corresponding column in the data reader with the same name.
   at System.Data.Query.InternalTrees.ColumnMapFactory.GetMemberOrdinalFromReader(DbDataReader storeDataReader, EdmMember member, EdmType currentType, Dictionary`2 renameList)
   at System.Data.Query.InternalTrees.ColumnMapFactory.GetColumnMapsForType(DbDataReader storeDataReader, EdmType edmType, Dictionary`2 renameList)
   at System.Data.Query.InternalTrees.ColumnMapFactory.CreateColumnMapFromReaderAndType(DbDataReader storeDataReader, EdmType edmType, EntitySet entitySet, Dictionary`2 renameList)
   at System.Data.Query.InternalTrees.ColumnMapFactory.CreateFunctionImportStructuralTypeColumnMap(DbDataReader storeDataReader, FunctionImportMapping mapping, EntitySet entitySet, StructuralType baseStructuralType)
   at System.Data.EntityClient.EntityCommandDefinition.FunctionColumnMapGenerator.System.Data.EntityClient.EntityCommandDefinition.IColumnMapGenerator.CreateColumnMap(DbDataReader reader)
   at System.Data.Objects.ObjectContext.CreateFunctionObjectResult[TElement](EntityCommand entityCommand, EntitySet entitySet, EdmType edmType, MergeOption mergeOption)
   at System.Data.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, MergeOption mergeOption, ObjectParameter[] parameters)
   at System.Data.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, ObjectParameter[] parameters)
   at Chinook.Model.ChinookEntities.GetVehicleDescFromModelId(Nullable`1 modelid) in C:\_Dev\Chinook\Source\Chinook.Model\Chinook.Designer.cs:line 160
   at Chinook.Model.GlassGuideDataProvider.GetVehicleFromModelId(Int32 ModelId) in C:\_Dev\Chinook\Source\Chinook.Model\GlassGuideDataProvider.cs:line 104
   at Chinook.Services.VehicleDataLookup.GetVehicleForRegistration(String reg) in C:\_Dev\Chinook\Source\Chinook\Services\VehicleDataLookup.asmx.cs:line 81
</pre>
<p>It seemed to be moaning that one of the columns in the complex type I set for it to use as the return type, doesn&#8217;t match to a column actually being returned, despite entity framework having auto generated that type itself!  The cause was, as is generally the case,  user error.  Inspecting the sproc a bit closer I noticed one of the columns was being returned twice, using the same name.  EF generated me a call with an iValuation and iValuation1 column, but failed to match iValuation1 because in reality both columns were simply called iValuation!  So a simple, and kind of obvious fix, but worth noting to stop someone else loose a little more hair when they&#8217;re confonted with this error!</p>


<p>Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/cross-apply-in-sql/' rel='bookmark' title='Cross Apply in SQL'>Cross Apply in SQL</a></li>
<li><a href='http://codeblog.shawson.co.uk/entity-framework-4-1-code-first-with-one-to-many-relationship-code-example/' rel='bookmark' title='Entity Framework 4.1 Code First (With One to Many relationship) Code Example'>Entity Framework 4.1 Code First (With One to Many relationship) Code Example</a></li>
<li><a href='http://codeblog.shawson.co.uk/asp-net-build-step-to-minify-and-obfuscate-your-sites-javascript-and-css/' rel='bookmark' title='Adding minification and obfuscation of your Javascript and CSS to your ASP.net build process using Yahoo YUI Compressor'>Adding minification and obfuscation of your Javascript and CSS to your ASP.net build process using Yahoo YUI Compressor</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://codeblog.shawson.co.uk/entity-framework-the-data-reader-is-incompatible-with-the-specified-complex-type/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ASP.net Roles and Membership installed to local SQL Express 2008 MDF file</title>
		<link>http://codeblog.shawson.co.uk/asp-net-roles-and-membership-installed-to-local-sql-express-2008-mdf-file/</link>
		<comments>http://codeblog.shawson.co.uk/asp-net-roles-and-membership-installed-to-local-sql-express-2008-mdf-file/#comments</comments>
		<pubDate>Sun, 05 Dec 2010 18:51:44 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[.net]]></category>
		<category><![CDATA[MVC]]></category>
		<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.shawson.co.uk/codeblog/?p=872</guid>
		<description><![CDATA[Just had an hour or so&#8217;s worth of ball-ache from this issue!  Working on an MVC2 site, i wanted to move the default membership out of the aspnet mdf file and into the sites main MDF file.  This should be a pretty simple web.config change, and a matter of running aspnet_regsql against the database.  I [...]


Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/how-to-run-sql-profiler-against-local-sql-express-instances/' rel='bookmark' title='How to run SQL Profiler against local SQL Express instances'>How to run SQL Profiler against local SQL Express instances</a></li>
<li><a href='http://codeblog.shawson.co.uk/asp-net-membership-log-times-incorrect-in-the-database/' rel='bookmark' title='ASP.net membership log times incorrect in the database'>ASP.net membership log times incorrect in the database</a></li>
<li><a href='http://codeblog.shawson.co.uk/collation-issues-setting-up-aspnet-membership-tables/' rel='bookmark' title='Collation issues setting up ASP.Net membership tables'>Collation issues setting up ASP.Net membership tables</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>Just had an hour or so&#8217;s worth of ball-ache from this issue!  Working on an MVC2 site, i wanted to move the default membership out of the aspnet mdf file and into the sites main MDF file.  This should be a pretty simple web.config change, and a matter of running aspnet_regsql against the database.  I<a href="http://rbgupta.blogspot.com/2007/03/aspnetregsql-with-sqlexpress-database.html"> read an article</a> mentioning that you can do this straight from the command line to your MDF file, but I had no success with this method- it simply created another database for me with a name equal to the full path of the database i had requested.  So I found I had to attach my database to my local sqlexpress instance, then run it against that;  so in sql;</p>
<pre class="brush: sql">

EXEC sp_attach_db &#039;mydb&#039;, N&#039;E:\_Dev\5imply\5imply-MVC2\BackOffice\App_Data\5imply.mdf&#039;
</pre>
<p>Then you can just run aspnet_regsql in the same way you would for any other database; In my example I just wanted Membership, roles and profiles</p>
<pre>C:\Windows\Microsoft.NET\Framework\v2.0.50727&gt;aspnet_regsql.exe -S .\SQLEXPRESS -d mydb -A mrp -E

Start adding the following features:
Membership
Profile
RoleManager

..

Finished.

C:\Windows\Microsoft.NET\Framework\v2.0.50727&gt;</pre>
<p>Then once you&#8217;re done, you can detach again;</p>
<pre class="brush: sql">

exec sp_detach_db &#039;mydb&#039;
</pre>
<p>Also- one other gotcha I found was that I had to do all this using SQL Management studio, having started it using &#8220;Run as Administrator&#8221;- I&#8217;m not sure if this is something specific to Windows 7, as  I would have expected to already be an administrator?  But I spent ages wondering why SQL refused to attach my database- Just kept getting an error &#8220;create file encountered operating system error 5&#8243; I eventually ran procmon and found it just didn&#8217;t have permisisons to the file under the account it was running under.</p>


<p>Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/how-to-run-sql-profiler-against-local-sql-express-instances/' rel='bookmark' title='How to run SQL Profiler against local SQL Express instances'>How to run SQL Profiler against local SQL Express instances</a></li>
<li><a href='http://codeblog.shawson.co.uk/asp-net-membership-log-times-incorrect-in-the-database/' rel='bookmark' title='ASP.net membership log times incorrect in the database'>ASP.net membership log times incorrect in the database</a></li>
<li><a href='http://codeblog.shawson.co.uk/collation-issues-setting-up-aspnet-membership-tables/' rel='bookmark' title='Collation issues setting up ASP.Net membership tables'>Collation issues setting up ASP.Net membership tables</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://codeblog.shawson.co.uk/asp-net-roles-and-membership-installed-to-local-sql-express-2008-mdf-file/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Changing the data type of a meta field in SiteFinity</title>
		<link>http://codeblog.shawson.co.uk/changing-the-data-type-of-a-meta-field-in-sitefinity/</link>
		<comments>http://codeblog.shawson.co.uk/changing-the-data-type-of-a-meta-field-in-sitefinity/#comments</comments>
		<pubDate>Fri, 15 Oct 2010 19:37:38 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[SQL Server]]></category>
		<category><![CDATA[Telerik SiteFinity CMS]]></category>

		<guid isPermaLink="false">http://www.shawson.co.uk/codeblog/?p=819</guid>
		<description><![CDATA[We have a site finity site which was nocked together by a designer who has since left- unfortunatly one of the meta field we had on the news articles &#8220;ViewCount&#8221; was set to ShortText instead of Integer, meaning we couldn&#8217;t do anything &#8220;numbery&#8221; with it&#8211; like sort it correctly (being text it sorted like 999- [...]


Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/setting-up-session-state-database-on-sql-server/' rel='bookmark' title='Setting up session state database on sql server'>Setting up session state database on sql server</a></li>
<li><a href='http://codeblog.shawson.co.uk/entity-framework-the-data-reader-is-incompatible-with-the-specified-complex-type/' rel='bookmark' title='Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;'>Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;</a></li>
<li><a href='http://codeblog.shawson.co.uk/sql-server-export-text-was-truncated-or-one-or-more-characters-had-no-match-in-the-target-code-page/' rel='bookmark' title='SQL Server Export : &#8220;Text was truncated or one or more characters had no match in the target code page&#8221;'>SQL Server Export : &#8220;Text was truncated or one or more characters had no match in the target code page&#8221;</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>We have a site finity site which was nocked together by a designer who has since left- unfortunatly one of the meta field we had on the news articles &#8220;ViewCount&#8221; was set to ShortText instead of Integer, meaning we couldn&#8217;t do anything &#8220;numbery&#8221; with it&#8211; like sort it correctly (being text it sorted like 999- 998- 90- 899- 898- 80 for example!), which was kind of crippling the &#8220;Most Popular&#8221; box on the homepage.</p>
<p>I read up that this is a simple matter of updating the entry for this meta field in the web config- easy enough (in the web.config under telerik > cmsEngine > metaFields);</p>
<pre class="brush: html">
&lt;!--&lt;add key=&quot;News.ViewCount&quot; valueType=&quot;ShortText&quot; visible=&quot;True&quot; searchable=&quot;True&quot; sortable=&quot;True&quot; defaultValue=&quot;&quot;/&gt;--&gt;
&lt;add key=&quot;News.ViewCount&quot; valueType=&quot;Integer&quot; visible=&quot;True&quot; searchable=&quot;True&quot; sortable=&quot;True&quot; defaultValue=&quot;0&quot;/&gt;
</pre>
<p>But unfortunly, this only applies to any data inserted after that change has taken place, and i had 6000 or so records already in the database as text.  Having dug around in the database I found the solution- meta data seems to be held in a table called sf_GCMetaData so having gradually built up a query which isolated my ViewCount fields i set about writing an update statement;</p>
<pre class="brush: sql">
UPDATE
                sf_GCMetaData
SET
                ValueType = 3,
                IntegerValue = CAST(ShortText AS Integer)
WHERE
                (Application = &#039;/News&#039;) AND (KeyValue = &#039;ViewCount&#039;) AND (ValueType = 0)
GO

UPDATE
                sf_GCMetaData
SET
                ShortText = null
WHERE
                (Application = &#039;/News&#039;) AND (KeyValue = &#039;ViewCount&#039;) AND (ValueType = 3)
</pre>
<p>A few notes- ValueType 0 is Shorttext, 3 is Integer- i figured this out by looking at other known meta fields.  So i move the data out of Shorttext and put it into IntegerValue field (using a cast to actually convert the data) then in a subsequent update i wipe out the shorttext data, incase this some how messes it up!</p>
<p>So conversion complete and nothing broke&#8211; <strong>try this at your own risk though and make sure you backup your databases first!!</strong></p>


<p>Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/setting-up-session-state-database-on-sql-server/' rel='bookmark' title='Setting up session state database on sql server'>Setting up session state database on sql server</a></li>
<li><a href='http://codeblog.shawson.co.uk/entity-framework-the-data-reader-is-incompatible-with-the-specified-complex-type/' rel='bookmark' title='Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;'>Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;</a></li>
<li><a href='http://codeblog.shawson.co.uk/sql-server-export-text-was-truncated-or-one-or-more-characters-had-no-match-in-the-target-code-page/' rel='bookmark' title='SQL Server Export : &#8220;Text was truncated or one or more characters had no match in the target code page&#8221;'>SQL Server Export : &#8220;Text was truncated or one or more characters had no match in the target code page&#8221;</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://codeblog.shawson.co.uk/changing-the-data-type-of-a-meta-field-in-sitefinity/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>SQL Server Export : &#8220;Text was truncated or one or more characters had no match in the target code page&#8221;</title>
		<link>http://codeblog.shawson.co.uk/sql-server-export-text-was-truncated-or-one-or-more-characters-had-no-match-in-the-target-code-page/</link>
		<comments>http://codeblog.shawson.co.uk/sql-server-export-text-was-truncated-or-one-or-more-characters-had-no-match-in-the-target-code-page/#comments</comments>
		<pubDate>Fri, 17 Sep 2010 14:57:35 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.shawson.co.uk/codeblog/?p=789</guid>
		<description><![CDATA[I recently did an export from a database table on a thirds party website we host, from the news letter table- Using the standard SQL Export dialogue in sql server management studio 2008, i selected to export to a flat file- i pasted in my query and adjusted the column mappings then hit finish only [...]


Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/wizard-generated-ssis-package-dumps-critical-files-in-temp-folder-breaks-after-a-log-out/' rel='bookmark' title='Wizard generated SSIS package dumps critical files in Temp folder- breaks after a log out!'>Wizard generated SSIS package dumps critical files in Temp folder- breaks after a log out!</a></li>
<li><a href='http://codeblog.shawson.co.uk/entity-framework-the-data-reader-is-incompatible-with-the-specified-complex-type/' rel='bookmark' title='Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;'>Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;</a></li>
<li><a href='http://codeblog.shawson.co.uk/ssis-dts-packages-violating-referential-integrity/' rel='bookmark' title='SSIS / DTS packages violating referential integrity'>SSIS / DTS packages violating referential integrity</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>I recently did an export from a database table on a thirds party website we host, from the news letter table- Using the standard SQL Export dialogue in sql server management studio 2008, i selected to export to a flat file- i pasted in my query and adjusted the column mappings then hit finish only to be confronted with an error mid way through the export;</p>
<blockquote><p>Copying to C:\Users\Shaw.Young\Desktop\bq-newsletters1.txt (Error)<br />
Messages<br />
Error 0xc02020a1: Data Flow Task 1: Data conversion failed. The data conversion for column &#8220;surname&#8221; returned status value 4 and status text &#8220;Text was truncated or one or more characters had no match in the target code page.&#8221;.<br />
(SQL Server Import and Export Wizard)</p>
<p>Error 0xc02020a0: Data Flow Task 1: Cannot copy or convert flat file data for column &#8220;surname&#8221;.<br />
(SQL Server Import and Export Wizard)</p>
<p>Error 0xc0047022: Data Flow Task 1: SSIS Error Code DTS_E_PROCESSINPUTFAILED.  The ProcessInput method on component &#8220;Destination &#8211; bq-newsletters1_txt&#8221; (46) failed with error code 0xC02020A0 while processing input &#8220;Flat File Destination Input&#8221; (47). The identified component returned an error from the ProcessInput method. The error is specific to the component, but the error is fatal and will cause the Data Flow task to stop running.  There may be error messages posted before this with more information about the failure.<br />
(SQL Server Import and Export Wizard)</p>
<p>Error 0xc02020c4: Data Flow Task 1: The attempt to add a row to the Data Flow task buffer failed with error code 0xC0047020.<br />
(SQL Server Import and Export Wizard)</p>
<p>Error 0xc0047038: Data Flow Task 1: SSIS Error Code DTS_E_PRIMEOUTPUTFAILED.  The PrimeOutput method on component &#8220;Source &#8211; Query&#8221; (1) returned error code 0xC02020C4.  The component returned a failure code when the pipeline engine called PrimeOutput(). The meaning of the failure code is defined by the component, but the error is fatal and the pipeline stopped executing.  There may be error messages posted before this with more information about the failure.<br />
(SQL Server Import and Export Wizard)</p></blockquote>
<p><div id="attachment_790" class="wp-caption alignright" style="width: 304px"><img class="size-medium wp-image-790" title="Export - Choose Destinatino Dialogue" src="http://www.shawson.co.uk/codeblog/wp-content/uploads/2010/09/export-294x300.jpg" alt="Export - Choose Destinatino Dialogue" width="294" height="300" /><p class="wp-caption-text">Export - Choose Destinatino Dialogue</p></div></p>
<p>I checked the mapping for the surname field, and at 100 characters it was the same as the field length so this wasn&#8217;t truncating, which left me with the codepage issue.  This is easily fixed by simply changing the encoding of the flat file all the way back on the Choose a Destination tab- Mine defaulted to &#8220;1252 (ANSI &#8211; Latin I)&#8221; so i changed it to &#8220;65001 (UTF &#8211; 8)&#8221; and this fixed the problem.  Really simple, but I&#8217;d actually never come across this before when doing an export so figured I would blog it.</p>


<p>Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/wizard-generated-ssis-package-dumps-critical-files-in-temp-folder-breaks-after-a-log-out/' rel='bookmark' title='Wizard generated SSIS package dumps critical files in Temp folder- breaks after a log out!'>Wizard generated SSIS package dumps critical files in Temp folder- breaks after a log out!</a></li>
<li><a href='http://codeblog.shawson.co.uk/entity-framework-the-data-reader-is-incompatible-with-the-specified-complex-type/' rel='bookmark' title='Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;'>Entity Framework &#8220;The data reader is incompatible with the specified complex type.&#8221;</a></li>
<li><a href='http://codeblog.shawson.co.uk/ssis-dts-packages-violating-referential-integrity/' rel='bookmark' title='SSIS / DTS packages violating referential integrity'>SSIS / DTS packages violating referential integrity</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://codeblog.shawson.co.uk/sql-server-export-text-was-truncated-or-one-or-more-characters-had-no-match-in-the-target-code-page/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>Clear down transaction logs</title>
		<link>http://codeblog.shawson.co.uk/clear-down-transaction-logs/</link>
		<comments>http://codeblog.shawson.co.uk/clear-down-transaction-logs/#comments</comments>
		<pubDate>Tue, 31 Aug 2010 08:47:41 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.shawson.co.uk/codeblog/?p=768</guid>
		<description><![CDATA[A bit of syntax that I can never remember off the top of my head! SQL 2005 &#8216;Transaction Log is Full on database xxx&#8217; DBCC SHRINKFILE(&#039;dbname_log&#039;, 1) BACKUP LOG dbname WITH TRUNCATE_ONLY DBCC SHRINKFILE(&#039;dbname_log&#039;, 1) Related posts:SQL Server truncate log Full Text Reindex, scheduled job has no steps! Grant Execute Permissions for all sprocs on [...]


Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/sql-server-truncate-log/' rel='bookmark' title='SQL Server truncate log'>SQL Server truncate log</a></li>
<li><a href='http://codeblog.shawson.co.uk/full-text-reindex-scheduled-job-has-no-steps/' rel='bookmark' title='Full Text Reindex, scheduled job has no steps!'>Full Text Reindex, scheduled job has no steps!</a></li>
<li><a href='http://codeblog.shawson.co.uk/grant-execute-permissions-for-all-sprocs-on-sql-2005/' rel='bookmark' title='Grant Execute Permissions for all sprocs on SQL 2005'>Grant Execute Permissions for all sprocs on SQL 2005</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>A bit of syntax that I can never remember off the top of my head!  SQL 2005 &#8216;Transaction Log is Full on database xxx&#8217;</p>
<pre class="brush: sql">
DBCC SHRINKFILE(&#039;dbname_log&#039;, 1)
BACKUP LOG dbname WITH TRUNCATE_ONLY DBCC SHRINKFILE(&#039;dbname_log&#039;, 1)
</pre>


<p>Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/sql-server-truncate-log/' rel='bookmark' title='SQL Server truncate log'>SQL Server truncate log</a></li>
<li><a href='http://codeblog.shawson.co.uk/full-text-reindex-scheduled-job-has-no-steps/' rel='bookmark' title='Full Text Reindex, scheduled job has no steps!'>Full Text Reindex, scheduled job has no steps!</a></li>
<li><a href='http://codeblog.shawson.co.uk/grant-execute-permissions-for-all-sprocs-on-sql-2005/' rel='bookmark' title='Grant Execute Permissions for all sprocs on SQL 2005'>Grant Execute Permissions for all sprocs on SQL 2005</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://codeblog.shawson.co.uk/clear-down-transaction-logs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Cross server queries in SQL Server</title>
		<link>http://codeblog.shawson.co.uk/cross-server-queries-in-sql-server/</link>
		<comments>http://codeblog.shawson.co.uk/cross-server-queries-in-sql-server/#comments</comments>
		<pubDate>Thu, 26 Aug 2010 09:29:07 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.shawson.co.uk/codeblog/?p=762</guid>
		<description><![CDATA[Without linking the servers you can do one off queries against another server using the OPENDATASOURCE or OPENROWSET functions. You will need to first enable &#8220;Ad Hoc Distributed Queries&#8221; as this is disabled by default- this can be achieved using sp_configure (if you&#8217;re logged in as sa) sp_configure &#039;Ad Hoc Distributed Queries&#039;, 1 reconfigure Once [...]


Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/setting-up-session-state-database-on-sql-server/' rel='bookmark' title='Setting up session state database on sql server'>Setting up session state database on sql server</a></li>
<li><a href='http://codeblog.shawson.co.uk/wizard-generated-ssis-package-dumps-critical-files-in-temp-folder-breaks-after-a-log-out/' rel='bookmark' title='Wizard generated SSIS package dumps critical files in Temp folder- breaks after a log out!'>Wizard generated SSIS package dumps critical files in Temp folder- breaks after a log out!</a></li>
<li><a href='http://codeblog.shawson.co.uk/cross-apply-in-sql/' rel='bookmark' title='Cross Apply in SQL'>Cross Apply in SQL</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>Without linking the servers you can do one off queries against another server using the OPENDATASOURCE or OPENROWSET functions.  You will need to first enable &#8220;Ad Hoc Distributed Queries&#8221; as this is disabled by default- this can be achieved using sp_configure (if you&#8217;re logged in as sa)</p>
<pre class="brush: sql">
sp_configure &#039;Ad Hoc Distributed Queries&#039;, 1
reconfigure
</pre>
<p>Once active you can use the function like this;</p>
<pre class="brush: sql">
SELECT
    *
FROM
    OPENDATASOURCE(&#039;SQLOLEDB&#039;, &#039;Data Source=&lt;servername&gt;;User ID=&lt;user&gt;;Password=&lt;password&gt;&#039;).&lt;dbname&gt;.&lt;dbo&gt;.&lt;tablename&gt;
</pre>
<p>There is also an OPENROWSET function;</p>
<pre class="brush: sql">
SELECT
    source.*
FROM
    OPENROWSET(&#039;SQLOLEDB&#039;, &#039;Data Source=&lt;servername&gt;;User ID=&lt;user&gt;;Password=&lt;password&gt;&#039;, &#039;SELECT * FROM &lt;dbname&gt;.&lt;dbo&gt;.&lt;tablename&gt;&#039;) as source
</pre>
<p>Thanks to Richard who dug this little nugget up from the interwebs.</p>


<p>Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/setting-up-session-state-database-on-sql-server/' rel='bookmark' title='Setting up session state database on sql server'>Setting up session state database on sql server</a></li>
<li><a href='http://codeblog.shawson.co.uk/wizard-generated-ssis-package-dumps-critical-files-in-temp-folder-breaks-after-a-log-out/' rel='bookmark' title='Wizard generated SSIS package dumps critical files in Temp folder- breaks after a log out!'>Wizard generated SSIS package dumps critical files in Temp folder- breaks after a log out!</a></li>
<li><a href='http://codeblog.shawson.co.uk/cross-apply-in-sql/' rel='bookmark' title='Cross Apply in SQL'>Cross Apply in SQL</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://codeblog.shawson.co.uk/cross-server-queries-in-sql-server/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Grant Execute Permissions for all sprocs on SQL 2005</title>
		<link>http://codeblog.shawson.co.uk/grant-execute-permissions-for-all-sprocs-on-sql-2005/</link>
		<comments>http://codeblog.shawson.co.uk/grant-execute-permissions-for-all-sprocs-on-sql-2005/#comments</comments>
		<pubDate>Tue, 24 Aug 2010 15:37:39 +0000</pubDate>
		<dc:creator>shawson</dc:creator>
				<category><![CDATA[SQL Server]]></category>

		<guid isPermaLink="false">http://www.shawson.co.uk/codeblog/?p=759</guid>
		<description><![CDATA[So I did a post for SQL 2000 aaages ago showing how to do this- it&#8217;s a lot easier in SQL 2005 but i always forget the syntax as i rarly have to use it. Open a new query editor on your selected database server then run this; use &#60;database_name&#62;; /* CREATE A NEW ROLE [...]


Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/assigning-execute-permissions-to-stored-procedure-in-bulk-on-sql-server-2000/' rel='bookmark' title='Assigning execute permissions to Stored procedure in bulk on sql server 2000'>Assigning execute permissions to Stored procedure in bulk on sql server 2000</a></li>
<li><a href='http://codeblog.shawson.co.uk/sql-2000-font/' rel='bookmark' title='SQL 2000 Font!'>SQL 2000 Font!</a></li>
<li><a href='http://codeblog.shawson.co.uk/how-to-run-sql-profiler-against-local-sql-express-instances/' rel='bookmark' title='How to run SQL Profiler against local SQL Express instances'>How to run SQL Profiler against local SQL Express instances</a></li>
</ul>]]></description>
			<content:encoded><![CDATA[<p>So I did a post for SQL 2000 aaages ago showing how to do this- it&#8217;s a lot easier in SQL 2005 but i always forget the syntax as i rarly have to use it.</p>
<p>Open a new query editor on your selected database server then run this;</p>
<pre class="brush: sql">
use &lt;database_name&gt;;
/* CREATE A NEW ROLE */
CREATE ROLE db_executor

/* GRANT EXECUTE TO THE ROLE */
GRANT EXECUTE TO db_executor
</pre>
<p>Then right click your database user (under security for the given database) and tick the new db_executor role.  You&#8217;re done!</p>


<p>Related posts:<ul><li><a href='http://codeblog.shawson.co.uk/assigning-execute-permissions-to-stored-procedure-in-bulk-on-sql-server-2000/' rel='bookmark' title='Assigning execute permissions to Stored procedure in bulk on sql server 2000'>Assigning execute permissions to Stored procedure in bulk on sql server 2000</a></li>
<li><a href='http://codeblog.shawson.co.uk/sql-2000-font/' rel='bookmark' title='SQL 2000 Font!'>SQL 2000 Font!</a></li>
<li><a href='http://codeblog.shawson.co.uk/how-to-run-sql-profiler-against-local-sql-express-instances/' rel='bookmark' title='How to run SQL Profiler against local SQL Express instances'>How to run SQL Profiler against local SQL Express instances</a></li>
</ul></p>]]></content:encoded>
			<wfw:commentRss>http://codeblog.shawson.co.uk/grant-execute-permissions-for-all-sprocs-on-sql-2005/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
	</channel>
</rss>

