Saturday, November 22, 2014

Exporting CLR Assemblies from SQL Server back to .dll files

Solution 1

Create a sql server project and import the database. It will import all the assemblies in the assemblies folder

How to set the database owner (DBO) has EXTERNAL ACCESS ASSEMBLY permission as TRUE?

EXEC sp_changedbowner 'sa'
ALTER DATABASE [dbase] SET trustworthy ON

asp net c# How do you convert Byte Array to Hexadecimal String, and vice versa?

public byte[] GetStringToBytes(string value)
{
 var shb = System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary.Parse(value);
 return shb.Value;
}
 
public string GetBytesToString(byte[] value)
{
 var shb = new System.Runtime.Remoting.Metadata.W3cXsd2001.SoapHexBinary(value);
 return shb.ToString();
}

Friday, November 14, 2014

Remove the last character in a string in T-SQL?

SELECT SUBSTRING( 'string' , 1 , LEN( 'string' ) - 1 )
--or
SELECT LEFT( 'string' , LEN( 'string' ) - 1 )

Thursday, November 13, 2014

Inner image and text of asp:LinkButton disappears after postback

This problem is now known to Microsoft, and they have published an official statement and workaround on the Microsoft Connect issue 718810: LinkButton controls collection lost on postback.
Microsoft statement is:
Thank you for the feedback. This seems like an oddity with the fact that the LinkButton control allows either direct text content via the Text property or in markup, or sub-controls via the Controls collection or markup. The workaround is to use a placeholder as the root content for the control and place the desired mixed content in there, e.g.
<asp:LinkButton runat="server">    <asp:PlaceHolder runat="server">        This is some text.</br>        <asp:Label runat="server">This is a control</asp:Label>    </asp:PlaceHolder>
</asp:LinkButton> 

Tuesday, November 11, 2014

“ClickOnce does not support the request execution level 'requireAdministrator.'”

Turns out that under the Security tab, "Enable ClickOnce security settings" was checked. Even though I didn't check it.

Anyway, unchecking that stopped ClickOnce giving me errors. That took a while to find...

Monday, November 10, 2014

.net How to allow a datetimepicker control to accept null value?

use the DateTimePicker controls Checked Property to determine where user has selected a value or not.
To Show Check inside DateTimePicker  control set the ShowCheckBox property to true
e.g.

DateTime? generatedOn = null;
if (dateTimePicker1.Checked)
    generatedOn = dateTimePicker1.Value;

Sunday, November 9, 2014

Load, save connection string in app.config dynamically

Code

Configuration config;
private void Form1_Load(object sender, EventArgs e)
{
    config = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
}
 
private void btnLoadSettings_Click(object sender, EventArgs e)
{
    System.Data.SqlClient.SqlConnectionStringBuilder cb = new System.Data.SqlClient.SqlConnectionStringBuilder();
    cb.ConnectionString = config.ConnectionStrings.ConnectionStrings["cs"].ConnectionString;
 
    boxServer.Text = cb.DataSource;
    boxUsername.Text = cb.UserID;
    boxPassword.Text = cb.Password;
    boxDatabase.Text = cb.InitialCatalog;
    cboxIntegratedSecurity.Checked = cb.IntegratedSecurity;
}
 
private void cboxIntegratedSecurity_CheckStateChanged(object sender, EventArgs e)
{
    pnlUserPass.Enabled = !cboxIntegratedSecurity.Checked;
}
 
private void btnSaveCS_Click(object sender, EventArgs e)
{
    System.Data.SqlClient.SqlConnectionStringBuilder cb = new System.Data.SqlClient.SqlConnectionStringBuilder();
 
    cb.DataSource = boxServer.Text;
    cb.UserID = boxUsername.Text;
    cb.Password = boxPassword.Text;
    cb.InitialCatalog = boxDatabase.Text;
    cb.IntegratedSecurity = cboxIntegratedSecurity.Checked;
 
    config.ConnectionStrings.ConnectionStrings["cs"].ConnectionString = cb.ConnectionString;
 
    config.Save(ConfigurationSaveMode.Modified);
    ConfigurationManager.RefreshSection("connectionStrings");
 
    MessageBox.Show("Connection string saved successfully");
}

Design


Friday, November 7, 2014

asp net How to register script at the very bottom of the page

Use the following
// Define the name and type of the client scripts on the page.
String csname1 = "PopupScript";
Type cstype = this.GetType();
 
// Get a ClientScriptManager reference from the Page class.
ClientScriptManager cs = Page.ClientScript;
 
// Check to see if the startup script is already registered.
if (!cs.IsStartupScriptRegistered(cstype, csname1))
{
    String cstext1 = "alert('Script at the bottom of form tag');";
    cs.RegisterStartupScript(cstype, csname1, cstext1, true);
}