Wednesday, July 21, 2010

Grant Permission for SQL User for Membership Provider using Database Role

The SQL User connecting to your Membershp Provider database (default named aspnetdb) should have the following database role:



Otherwise you will get the following error:

EXECUTE permission denied on object 'aspnet_CheckSchemaVersion', database 'aspnetdb', schema 'dbo'.

Connection String for Membership Provider using a Trusted Connection over TCP/IP on a specific Port

<add name="LocalSqlServer"

  connectionString="Data Source=,2116;

                    Network Library=DBMSSOCN;

                    Initial Catalog=aspnetdb;

                    Integrated Security=SSPI;"/>


Tuesday, July 20, 2010

Using data binding with Eval to set TemplateField button Visible property

I needed to conditionally hide a delete button in a GridView. This data binding expression did the trick:

<asp:ImageButton ID="ImageButton1" runat="server" CausesValidation="False"
CommandName="Delete" ImageUrl="~/_Images/cross.png" Text="Delete"
Visible='<%# ((string)Eval("statuscodeLabel") == "Draft") %>' />

I also ran across this little beauty that calls a DAL class to do a check against the database (the data is hopefully cached):

<asp:HyperLink ID="lnkCert" runat="server"
Visible='<%# SomeDAL.UserCanDoSomething(CType(Container.DataItem, System.Data.DataRowView).Item("Code").ToString()) %>'
NavigateUrl='<%# Eval("ID", "~/forms/AgencyForm.aspx?pid={0}&mode=cert") %>'>
<img src="../images/tick.png" alt="Certify Agency Data" /></asp:HyperLink>

Saturday, July 17, 2010

Pride goeth before a fall

I assure you...this did not end well.

Friday, July 16, 2010

Using CRM Advanced Developer Extensions to Add Attachment to Contact

This code sample is straight from MSDN, but it is so often used, I wanted to make sure I kept it handy:


// Add a note with a document attachment to the contact's record.

var attachment = File.OpenRead("capture.png");

var data = new byte[attachment.Length];

attachment.Read(data, 0, (int)attachment.Length);


var note = new Xrm.annotation()


  subject = "Note subject...",

  notetext = "Note Details....",

  Contact_Annotation_id = contact.contactid,

  objecttypecode = "contact",

  documentbody = Convert.ToBase64String(data),

  filename = Path.GetFileName(attachment.Name),

  mimetype = "image/png"






Friday, July 9, 2010

Retrieve CRM Entity's Picklist using MetadataService

This method returns a NameValueCollection of picklist items. CrmHelper is similar to the SDK utility sample.

public NameValueCollection GetAgencyRelationshipTypePicklist()
CrmHelper helper = new CrmHelper();

NameValueCollection picklist = new NameValueCollection();

RetrieveAttributeRequest attribReq = new RetrieveAttributeRequest();
attribReq.EntityLogicalName = "new_agencycontact";
attribReq.LogicalName = "new_agencycontacttype";
attribReq.RetrieveAsIfPublished = true;

MetadataService service = helper.GetMetadataService();

RetrieveAttributeResponse attribResp = service.Execute(attribReq) as RetrieveAttributeResponse;

PicklistAttributeMetadata listData = attribResp.AttributeMetadata as PicklistAttributeMetadata;

foreach (Option item in listData.Options)
picklist.Add(item.Value.formattedvalue, item.Label.UserLocLabel.Label);

return picklist;

Use JavaScript to hide an ASP.Net Button

To be 508 compliant, my page must allow users to select items from a drop-down list with JavaScript disabled, so I added a “select” button (called btnAgSelect) next to the list.  When JS is enabled, I do not want the button to be visible, so I used this in my Page.Load() event:



  this ,this.GetType(),

  "", "document.getElementById('" +

  btnAgSelect.ClientID + "').style.visibility='hidden';",


Saturday, July 3, 2010

Windows XP Standby Wakes Up

I got a new work laptop that I typically left on Standby, but it kept waking up in the middle of the night and draining the battery.  I assumed it was the NIC’s Wake-On-LAN setting so I disabled the following setting (note the OS warning that someone had obviously ignored) using Hardware Manager (System – Hardware tab):