IIS Permissions and the IIS_IUSR role

some web applications need access to the “temporary asp.net files” folder. The IIS_IUSR role already has read/write access to it but sometimes (i.e. the ePortfolio system) it needs to create a folder and can’t do that, even when the AppPoolIdentity account is a member of the IIS_IUSR role. In that case I just created the folder and it was fine… There could be a further problem when the AppPoolIdentity is a domain account: http://www.yusufozturk.info/iis7/asp-net-write-access-error-on-iis7-5.html

January 24, 2012 · 1 min

Enabling WCF web services in IIS7

would never have figured this one out: http://stackoverflow.com/questions/3188618/enabling-net-tcp

January 20, 2012 · 1 min

Referencing assemblies in the GAC in Visual Studio

Use this Visual Studio add in http://visualstudiogallery.msdn.microsoft.com/36a6eb45-a7b1-47c3-9e85-09f0aef6e879/

October 21, 2011 · 1 min

Beware of entity tracking

Entity tracking is clever and manages to keep a cache of recently used entities (and lists of entities) and, if it doesn’t see a change to an entity, it will return the cached version without going to the database – that’s what caching is after all. The problem is that ALL changes to the database MUST be made by the same project using .netTiers methods. If you’re developing an application and change data directly in the database then .netTiers won’t spot that. Pretty obvious really but do remember whether you have enableEntityTracking="true" or enableEntityTracking="false" in the SqlNetTiersProvider bit of your web.config

August 16, 2011 · 1 min

useStoredProcedure=true but still runs SELECT statements

.netTiers can be configured to only use stored procedures, which is a great way to reduce the possibility of the database being attacked as the user account can be given access to only execute stored procedures and not have any direct access to the tables. To do this, just set useStoredProcedure=true in the netTiers <providers> section of the web.config If you do this, some pages (methods) will still need SELECT access to tables. By default, netTiers creates entitygridviews that use paging and so use the get_paged method, which calls the myTable_GetPaged stored procedure. This stored procedure builds a couple of SQL strings (SELECT statements) that are executed, which means that the user account needs to have access to run SELECT statements. To give SELECT access to all tables in the database, you can add the user account to the db_datareader role.

June 3, 2011 · 1 min

Getting the ID of a newly inserted record

if you’re using a <data:MultiFormView ID="FormView1"> bound to a <data:MyTableDataSource> then it isn’t obvious how to get the ID of a record that you’ve just inserted e.g. you might want to redirect back to the same form but with the new ID in the querystring to further edit the form or related information. This is all you need to do: protected void FormView1_ItemInserted(Object sender, EventArgs e) { int Myid = BMyTableDataSource.EntityId.Myid; }

April 18, 2011 · 1 min

Using the description property of SQL Server fields as the friendly name

SQL Server allows each field in the database to have a description, so this description seems like the most useful place to put friendly names for fields that will appear on a netTiers generated admin page. When netTiers first runs, a config file is generated as specified in 01 MappingFile This XML file lists all of the tables and for each table it lists all of the fields e.g. <Column Id="title" CSType="System.String" PropertyName="Title" FieldName="_title" FriendlyName="Title" IncludeInOutput="true" /> netTiers will automatically convert the database field name of “title” to a FriendlyName of “Title” It’s quite clever too and will convert a field name of "title_or_salutation" to a FriendlyName of "Title Or Salutation" ...

March 17, 2011 · 2 min

Using stored procedures in entity data sources

The normal <asp:SqlDataSource/> can use stored procedures as the select method and even for insert/update/delete commands. netTiers will create a strongly typed data source for each table. The inserts, updates and deletes are handled automatically but there are options for which records to select. Get_Paged is the default but you can also get by any foreign key. Sometimes this isn’t enough and you want a custom filter for your entities. To do this, write a stored procedure that returns all of the columns in the base table and no other columns. The SP can have joins to other tables, so you can use those for filtering. The SP can have whatever parameters you like. Because the SP returns all of the columns of the base table, netTiers recognises that it can be used to get a list of entities and so allows it as a SelectMethod e.g. ...

February 18, 2011 · 2 min

transactions and creating related records on insert

After creating a record, you might want to automatically create a related child record, which uses the ID of the record you have just created. In your datasource <data:XyzDataSource> you can put in OnInserted="Xyz_Inserted": <data:XyzDataSource ID="XyzDataSource" runat="server" SelectMethod="GetById" OnInserted="Xyz_Inserted"> protected void Xyz\_Inserted(Object sender, ObjectDataSourceStatusEventArgs e) { if (e.Exception == null) { if (FormView1.CurrentMode == FormViewMode.Insert) { Xyz myXyz = (Xyz)e.ReturnValue; int ID = myXyz .Id; // now create the child entity, set the parent id and insert it } } } The problem with this is that netTiers by default uses transactions and Xyz_Inserted is called in the middle of the transaction. So, whilst an ID has been returned for the new record, it hasn’t been committed to the database, so you can’t create the child record yet. The way around this is for the datasource to not use transactions. ...

February 9, 2011 · 1 min

Database connections timing out in IIS 7.5 – caused by EntityTransactionModule

Problem: After using a netTiers powered website for a while, the database connections would start to time out and you’d get a Stack Trace like: at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) at System.Data.SqlClient.TdsParserStateObject.ReadSniError(TdsParserStateObject stateObj, UInt32 error) Solution: NetTiers was using an EntityTransactionModule which was incorrectly configured. It was opening database connections and not closing them (I think) and so SQL Server eventually stops allowing connections. IIS 7.5 needs the following code in the web.config to correctly configure the module. ...

February 8, 2011 · 1 min