WCF exception: Security settings for this service require 'Anonymous' Authentication but it is not enabled for the IIS application that hosts this service.

Security settings for this service require ‘Anonymous’ Authentication but it is not enabled for the IIS application that hosts this service.

image

This error occurred, because I had an endpoint configured in mine wcf service web.config with a identity tag, as shown below:

<endpoint address="" binding="wsHttpBinding" contract="Tpp.Pegaso.MaintenanceService.IMaintenanceService">
    <identity>
<dns value="localhost"/>
</identity>
</endpoint>

This identity element should be removed or replaced to reflect the identity under which the deployed service runs. If removed, WCF will infer an appropriate identity automatically.

To avoid disclosing metadata information, I set the serviceMetadata httpGetEnabled to false:

<serviceMetadata httpGetEnabled="true"/>

and removed the mex endpoint:

<endpointaddress="mex" binding="mexHttpBinding" contract="IMetadataExchange"/>

ASP .NET error: No protocol binding matches the given address 'http://…./ImportService.svc'. Protocol bindings are configured at the Site level in IIS or WAS configuration.

I got the asp .net error: No protocol binding matches the given address ‘http://…./ImportService.svc’. Protocol bindings are configured at the Site level in IIS or WAS configuration, because I did not do an iisreset after I changed the website binding (I added a hostheader).

image

Display used and free space with TSQL in Microsoft SQL Server 2008 mdf and ldf file

To calculate the "size", "used size in" and "free space in" a Microsoft SQL Server 2008 mdf or ldf file use:

use master

go
select
name, cast((size/128.0) as int) as TotalSpaceInMB, cast((cast(fileproperty(name, 'SpaceUsed') as int)/128.0) as int) as UsedSpaceInMB, cast((size/128.0 - cast(fileproperty(name, 'SpaceUsed') AS int)/128.0) as int) as FreeSpaceInMB from sys.database_files

Result

image 

For more information on fileproperty, see: http://msdn.microsoft.com/en-us/library/ms188401.aspx

Import data from Microsoft Office Access 2007 to Microsoft SQL Server 2008

There are several ways to import data from Microsoft Office Access to Microsoft SQL Server, but I decided to import de data from Microsoft Access into a Microsoft SQL Server table with "the same" columns and types and made all columns nullable to avoid import errors and then created a TSQL script to move the data to the destination table with different columns and types. This was, because I know a lot about Microsoft SQL Server and less about Microsoft Access.

Table in Microsoft Access
image

Import Table in Microsoft SQL Server
create table dbo.PostcodeImport
(
 
Id int not nullidentity(1,1)primary key,
 
Postcode varchar(6) null,
 
Series varchar(1) null,
 
[Huisnummer van] int,
 
[Huisnummer t/m] int,
 
Plaats varchar(24) null,
 
Straat varchar(28) null
)
go

To import the data in the "PostcodeImport" table:
> Open Microsoft SQL Server 2008 Management Studio
> Right click you’re database > Tasks > Import Data …
> On SQL Server Import and Export Wizard screen 1 click Next
> On SQL Server Import and Export Wizard screen 2 choose Data source: Microsoft Access
    Then click on Browse to select the Microsoft Access file
image
> On SQL Server Import and Export Wizard screen 3 choose Destination: SQL Server native Client 10.0, the enter you’re SQL Server name.
> Enter the database name
image
> On SQL Server Import and Export Wizard screen 4 choose "Copy data from one or more tables or views"
> On SQL Server Import and Export Wizard screen 5 choose Source table "Postcode" and destination table "PostcodeImport"
image
> We don’t have to edit the column mappings, because the columns have the same names and types
> Click on Next
> On SQL Server Import and Export Wizard screen 6 click Next
> On SQL Server Import and Export Wizard screen 7 click Next
> On SQL Server Import and Export Wizard screen 8 click Finish
image 
> Click on Close

Use a TSQL script to move the data from the PostcodeImport table to the Postcode table

insert into
Postcode (Postcode,Straatnaam,Plaats,RangeStart,RangeEind,PostcodetypeId)
select distinct p.Postcode,p.Straat,p.Plaats,p.[Huisnummer van],p.[Huisnummer t/m],
cast (
  
case
        when
p.Series =‘ ‘ then1
        when p.Series is null then1
        when p.Series =then1
        else p.Series
    end
as int
)
from PostcodeImport p

Microsoft Office Sharepoint Server Automaticly sign-on with Windows Username and password

http://www.experts-exchange.com/OS/Microsoft_Operating_Systems/Server/MS-SharePoint/Q_22988684.html

in IE, go to Internet options.  go to the security tab.  highlight Local Intranet and then click Custom Level.  at the bottom of the settings, make sure "automatic logon with current user name and password" is selected.  then click ok.  make sure Local Intranet is still highlighted and click the button called Sites.  in IE 7, i see a box that has an Advanced button.  click Advanced.  in IE 6, i think it just takes you to that page where you can verify that your sharepoint site is listed.  if it’s not listed, add it in.

IE will then automatically log users in.

Shortcut Collapse project or projects in the Solution Explorer Microsoft Visual Studio 2008

The standard windows keyboard shortcuts for expanding and collapsing treeviews are:
Numeric Keypad *: Expands everything under the current selection
Numeric Keypad +: Expands the current selection
Numeric Keypad -: Collapses the current selection.
RIGHT ARROW: Expands the current selection if it is not expanded, otherwise goes to the first child
LEFT ARROW: Collapses the current selection if it is expanded, otherwise goes to the parent
All keyboard shortcuts work in the Microsoft Visual Studio 2008 explorer except for the collapse on the solution.

If you want all files in a solution to be collapsed use the tool: PowerCommands for Microsoft Visual Studio 2008: http://code.msdn.microsoft.com/PowerCommands
It adds a command: Collapse Projects:
This command collapses a project or projects in the Solution Explorer starting from the root selected node. Collapsing a project can increase the readability of the solution. This command can be executed from three different places: solution, solution folders and project nodes respectively.

Month abbreviation in C#

If you want to use dates in C# like 20-mar-2009, you have to know the month abbreviation, for en-US these are:

Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20080101", "yyyyMMdd", newCultureInfo( "en-US", false))));
Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20080201", "yyyyMMdd", newCultureInfo("en-US", false))));
Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20080301", "yyyyMMdd", newCultureInfo("en-US", false))));
Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20080401", "yyyyMMdd", newCultureInfo("en-US", false))));
Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20080501", "yyyyMMdd", newCultureInfo("en-US", false))));
Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20080601", "yyyyMMdd", newCultureInfo("en-US", false))));
Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20080701", "yyyyMMdd", newCultureInfo("en-US", false))));
Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20080801", "yyyyMMdd", newCultureInfo("en-US", false))));
Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20080901", "yyyyMMdd", newCultureInfo("en-US", false))));
Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20081001", "yyyyMMdd", newCultureInfo("en-US", false))));
Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20081101", "yyyyMMdd", newCultureInfo("en-US", false))));
Console.WriteLine(string.Format("{0:MMM}", DateTime.ParseExact("20081201", "yyyyMMdd", newCultureInfo("en-US", false))));

/*

Result:
    Jan
    Feb
    Mar
    Apr
    May
    Jun
    Jul
    Aug
    Sep
    Oct
    Nov
    Dec

*/

Convert byte [] array to hex string

/// <summary>
/// Convert a byte array to a hex string
/// </summary>
/// <param name="bytes"></param>
/// <returns>
///     Converted byte array to string
///     null, when bytes == null
/// </returns>
public string ConvertByteArrayToString(byte[] bytes)
{
string result = null;
// Convert byte array to string, when bytes is not null
if (bytes != null)
{
result = BitConverter.ToString(bytes);
result = result.Replace("-", string.Empty);
}
return result;
}

Insert image with TSQL and a hex string

You can insert an image from t-sql script, if you use the hex string notation:
The next line will insert an image representing a "check mark" into the database. In a table [Test] with a column [Image].

insert
    [Test]
values(0x89504E470D0A1A0A0000000D49484452000000100000001008060000001FF3FF61000000017352474200AECE1CE90000000467414D410000B18
F0BFC6105000000206348524D00007A26000080840000FA00000080E8000075300000EA6000003A98000017709CBA513C000001B649444154384FA5926B
2F42711CC77924E7BDB8970873DB58AE4B11399CC8359A2754A7D23D86B91C0FCDFD3A5B68AEC36C1E2AC9780DE64D485FFFCEA68D329AB39D87DFCBEFF
3FFA60248F9D71735F8CF9FB458B9D9C035ADD4D83E43933268D9A8E774271A0C1E319072E52C7FFE5FEB37AFD771C3C7DD987F72C27367827A578952778
1F94F068AB55A4EEB5363F6D18199471BBAF65A51E62984C42A14C40CB4D74C65FF05DDFBBD917CB5968B569E0ED93015B2F2C9254E71B8703C4F103B417BC
514F79DD3AFECAD0E8CB779E4D384C0E2060E3B31F5308EC9070B989D16143BF2C305965C5ECC1B0C5E7656F59DB5BF4CF859CC86EC50EDCAC204D6886C5
93AD37F4063226881E79E45C7B602457651586CCE89897983DE5355BAC6D706FDCD10169EDDF0F84DD01EABA13BD5C0E537C2796F04BD2587C4267CCF37
7D15C74EA0F7E5144986EE4CC3DF391934C311D0C3E1D743B5D914851511B1D95F92E376406051B225297ABCED70060CB0DE8DA26D5D06022B223266251
4C7ED40BA584155CF9591CA0A28D71A4160458486CC1FC5098744DE972A71894160BDE5E933D37E1B5AC221115854EE58C6AFE2A4A6FC53930F93387C6A
1968F12D0000000049454E44AE426082)

 

Note

Some times, Microsoft SQL Server Management Studio will add a "zero" at the beginning, like 0x08950….
In this case add a "zero" at the end of the hex value, like:
insert [Test] values (0x8950……0)

Then magically the data will be correctly inserted into the database, see also: http://stackoverflow.com/questions/2657922/insert-hex-string-value-to-sql-server-image-field-is-appending-extra-0

C# convert a BitMap to Byte[]

/// <summary>
/// Covert a bitmap to a byte array
/// </summary>
/// <param name="bitmap"></param>
/// <returns>
/// byte array, when bitmap could be converted
/// null, when bitmap is null
/// null, when bitmap could not be converted to byte array
/// </returns>
public byte[] ConvertBitMapToByteArray(Bitmap bitmap)
{
byte[] result = null;
if (bitmap != null)
{
MemoryStream stream = new MemoryStream();
bitmap.Save(stream, bitmap.RawFormat);
result = stream.ToArray();
}
return result;
}