Tag Archives: .net

Dynamically Populating Dropdownlists

Had to do this today, took a few minutes of google searching

In order to dynamically populate a drop down list use the following logic:

SqlConnection connection = new SqlConnection(connectionString);
connection.Open();
string query = “SELECT STUFF1, [STUFF2] FROM STUFFTABLE”;
SqlCommand command = new SqlCommand(query, connection);
SqlDataReader reader = command.ExecuteReader();
lstAppointmentType.DataSource = reader;
lstAppointmentType.DataTextField = “STUFF1”;
lstAppointmentType.DataValueField = “STUFF2”;
lstAppointmentType.DataBind();
reader.Close();

Easy stuff once you see it done. Note the column with [] around it is shown so you know to not include the []s when you add to the list.

Cheers

An error occurred in the Microsoft .NET Framework while trying to load assembly

I received this error after deployment of a new Sql CLR function:

An error occurred in the Microsoft .NET Framework while trying to load assembly id 65545. The server may be running out of resources, or the assembly may not be trusted with PERMISSION_SET = EXTERNAL_ACCESS or UNSAFE. Run the query again, or check documentation to see how to solve the assembly trust issues. For more information about this error:
System.IO.FileLoadException: Could not load file or assembly ‘sqlclr, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null’ or one of its dependencies. An error relating to security occurred. (Exception from HRESULT: 0x8013150A)
System.IO.FileLoadException:
at System.Reflection.Assembly._nLoad(AssemblyName fileName, String codeBase, Evidence assemblySecurity, Assembly locationHint, StackCrawlMark& stackMark, Boolean throwOnFileNotFound, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(AssemblyName assemblyRef, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.InternalLoad(String assemblyString, Evidence assemblySecurity, StackCrawlMark& stackMark, Boolean forIntrospection)
at System.Reflection.Assembly.Load(String assemblyString)

I found the following solution that seems to work:

Turn on the Trustworthy flag on the database you are deploying to using:

ALTER DATABASE YOURDATABASENAME
SET TRUSTWORTHY ON

After that the clr assembly should have no problem running.

Cheers

Ajax Modal Popup and the Field Validators

In one of my web application projects I wanted to create some modal popups that would collect user input and validate. I ran into an error using required field validators and regular expression validators.

The modal popup would show as normal and if the validators would trigger on bad input. Once a validator was triggered, if the user cancelled the modal popup they would no longer be able to activate any controls on the page.

o_O

Always put your validation controls in a validation group, this will prevent a few headaches you may run into. If you have multiple modal popup forms, put each forms validation controls in their own validation groups.

Cheers