Sunday, December 23, 2012

Run Tings Proper: SOLVED: "Visual Studio setup cannot run in compati...

Run Tings Proper: SOLVED: "Visual Studio setup cannot run in compati...: If you are having problems upgrading from Visual Studio 2010 Beta 2 to Release Candidate (RC1) then hopefully this will get you back on your...

Wednesday, November 28, 2012

Resolve : SQL Server Express CREATE DATABASE permission denied in database 'master'

Please check the below stackoverflow reference.

http://stackoverflow.com/questions/1616515/sql-server-express-create-database-permission-denied-in-database-master

From the above link I found the reference to the script form microsoft site and that solved the issue.

The script is :


@echo off
rem
rem ****************************************************************************
rem
rem    Copyright (c) Microsoft Corporation. All rights reserved.
rem    This code is licensed under the Microsoft Public License.
rem    THIS CODE IS PROVIDED *AS IS* WITHOUT WARRANTY OF
rem    ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING ANY
rem    IMPLIED WARRANTIES OF FITNESS FOR A PARTICULAR
rem    PURPOSE, MERCHANTABILITY, OR NON-INFRINGEMENT.
rem
rem ****************************************************************************
rem
rem CMD script to add a user to the SQL Server sysadmin role
rem
rem Input:  %1 specifies the instance name to be modified. Defaults to SQLEXPRESS.
rem         %2 specifies the principal identity to be added (in the form "<domain>\<user>").
rem            If omitted, the script will request elevation and add the current user (pre-elevation) to the sysadmin role.
rem            If provided explicitly, the script is assumed to be running elevated already.
rem
rem Method: 1) restart the SQL service with the '-m' option, which allows a single connection from a box admin
rem            (the box admin is temporarily added to the sysadmin role with this start option)
rem         2) connect to the SQL instance and add the user to the sysadmin role
rem         3) restart the SQL service for normal connections
rem
rem Output: Messages indicating success/failure.
rem         Note that if elevation is done by this script, a new command process window is created: the output of this
rem         window is not directly accessible to the caller.
rem
rem
setlocal
set sqlresult=N/A
if .%1 == . (set /P sqlinstance=Enter SQL instance name, or default to SQLEXPRESS: ) else (set sqlinstance=%1)
if .%sqlinstance% == . (set sqlinstance=SQLEXPRESS)
if /I %sqlinstance% == MSSQLSERVER (set sqlservice=MSSQLSERVER) else (set sqlservice=MSSQL$%sqlinstance%)
if .%2 == . (set sqllogin="%USERDOMAIN%\%USERNAME%") else (set sqllogin=%2)
rem remove enclosing quotes
for %%i in (%sqllogin%) do set sqllogin=%%~i
@echo Adding '%sqllogin%' to the 'sysadmin' role on SQL Server instance '%sqlinstance%'.
@echo Verify the '%sqlservice%' service exists ...
set srvstate=0
for /F "usebackq tokens=1,3" %%i in (`sc query %sqlservice%`) do if .%%i == .STATE set srvstate=%%j
if .%srvstate% == .0 goto existerror
rem
rem elevate if <domain/user> was defaulted
rem
if NOT .%2 == . goto continue
echo new ActiveXObject("Shell.Application").ShellExecute("cmd.exe", "/D /Q /C pushd \""+WScript.Arguments(0)+"\" & \""+WScript.Arguments(1)+"\" %sqlinstance% \""+WScript.Arguments(2)+"\"", "", "runas"); >"%TEMP%\addsysadmin{7FC2CAE2-2E9E-47a0-ADE5-C43582022EA8}.js"
call "%TEMP%\addsysadmin{7FC2CAE2-2E9E-47a0-ADE5-C43582022EA8}.js" "%cd%" %0 "%sqllogin%"
del "%TEMP%\addsysadmin{7FC2CAE2-2E9E-47a0-ADE5-C43582022EA8}.js"
goto :EOF
:continue
rem
rem determine if the SQL service is running
rem
set srvstarted=0
set srvstate=0
for /F "usebackq tokens=1,3" %%i in (`sc query %sqlservice%`) do if .%%i == .STATE set srvstate=%%j
if .%srvstate% == .0 goto queryerror
rem
rem if required, stop the SQL service
rem
if .%srvstate% == .1 goto startm
set srvstarted=1
@echo Stop the '%sqlservice%' service ...
net stop %sqlservice%
if errorlevel 1 goto stoperror
:startm
rem
rem start the SQL service with the '-m' option (single admin connection) and wait until its STATE is '4' (STARTED)
rem also use trace flags as follows:
rem     3659 - log all errors to errorlog
rem     4010 - enable shared memory only (lpc:)
rem     4022 - do not start autoprocs
rem
@echo Start the '%sqlservice%' service in maintenance mode ...
sc start %sqlservice% -m -T3659 -T4010 -T4022 >nul
if errorlevel 1 goto startmerror
:checkstate1
set srvstate=0
for /F "usebackq tokens=1,3" %%i in (`sc query %sqlservice%`) do if .%%i == .STATE set srvstate=%%j
if .%srvstate% == .0 goto queryerror
if .%srvstate% == .1 goto startmerror
if NOT .%srvstate% == .4 goto checkstate1
rem
rem add the specified user to the sysadmin role
rem access tempdb to avoid a misleading shutdown error
rem
@echo Add '%sqllogin%' to the 'sysadmin' role ...
for /F "usebackq tokens=1,3" %%i in (`sqlcmd -S np:\\.\pipe\SQLLocal\%sqlinstance% -E -Q "create table #foo (bar int); declare @rc int; execute @rc = sp_addsrvrolemember '$(sqllogin)', 'sysadmin'; print 'RETURN_CODE : '+CAST(@rc as char)"`) do if .%%i == .RETURN_CODE set sqlresult=%%j
rem
rem stop the SQL service
rem
@echo Stop the '%sqlservice%' service ...
net stop %sqlservice%
if errorlevel 1 goto stoperror
if .%srvstarted% == .0 goto exit
rem
rem start the SQL service for normal connections
rem
net start %sqlservice%
if errorlevel 1 goto starterror
goto exit
rem
rem handle unexpected errors
rem
:existerror
sc query %sqlservice%
@echo '%sqlservice%' service is invalid
goto exit
:queryerror
@echo 'sc query %sqlservice%' failed
goto exit
:stoperror
@echo 'net stop %sqlservice%' failed
goto exit
:startmerror
@echo 'sc start %sqlservice% -m' failed
goto exit
:starterror
@echo 'net start %sqlservice%' failed
goto exit
:exit
if .%sqlresult% == .0 (@echo '%sqllogin%' was successfully added to the 'sysadmin' role.) else (@echo '%sqllogin%' was NOT added to the 'sysadmin' role: SQL return code is %sqlresult%.)
endlocal
pause




Tuesday, October 23, 2012

NANT : xmlpeek and namespaces

 <xmlpeek
      file="${prjconfig}"
      xpath="Project/ExeName"
      property="newexe"
      failonerror="false"/>
fails on XML like:   <?xml version="1.0" encoding="utf-8"?>
<Project xmlns="http://nant.sf.net/release/0.86-beta1/nant.xsd">
  <ExeName>foo</ExeName>
</Project>   
The reason is namespace associated with XML file. To enable this we have to extend xmlpeek task to be namespace-aware. 
I suggest this syntax:   <xmlpeek
      file="${prjconfig}"
      xpath="x:Project/x:ExeName"       property="newexe"
      failonerror="false">         <namespace name="x" ns="http://nant.sf.net/release/0.86-beta1/nant.xsd"/> </xmlpeek>

Friday, September 14, 2012

Troubleshooting:Database diagram support objects cannot be installed because this database does not have a valid owner

The fix for this issue is described in following link


I know the content of above link will never disappear, still here is the copy of the content from the above link
Error:
Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects.
Workaround / Fix / Solution :
Well for a while I attempted few things and nothing worked. After that I carefully read the error and I realized that solution was proposed in the error only. I just have to read it carefully. Here are the steps I did to make this work.
-- Replace YourDatabaseName in following scriptALTER AUTHORIZATION ON DATABASE::YourDatabaseName TO sa
GO
  • Select your database >> Right Click >> Select Properties
  • Select FILE in left side of page
  • In the OWNER box, select button which has three dots (…) in it
  • Now select user ‘sa’ or NT AUTHORITY\SYSTEM and click OK.
This should solve your problem.
Please note, I suggest you check your security policies before changing authorization. I did this to quickly solve my problem on my development server. If you are on production server, you may open yourself to potential security compromise. 

Thursday, September 6, 2012

Troubleshooting : HTTP could not register URL http://+:8080/AppName/ServiceName/ because TCP port 8080 is being used by another application.

Reference URL :

http://saravananarumugam.wordpress.com/2011/03/25/http-could-not-register-url-http80temporary_listen_addresses634f73f6-c612-4441-acf8-79ddd5c62f98-because-tcp-port-80-is-being-used-by-another-application/

http://saravananarumugam.wordpress.com/2011/03/01/http-could-not-register-url/

-------------------------------------------------
Content From above URLs
----------------------

Article1
When I used a Duplex channeled binding (wsDualHttpBinding), during the run time I received the following exception.
Exception:
HTTP could not register URL http://+:80/Temporary_Listen_Addresses/634f73f6-c612-4441-acf8-79ddd5c62f98/ because TCP port 80 is being used by another application.
This is because the port 80 is being used by the IIS (the default web site uses Port 80) and the callback from the service attempts to register the same port for communication.
Solution:
The solution to this is to instruct the WCF to use a different port. I had to add the following binding configuration.
    <bindings>
      <wsDualHttpBinding>
        <binding name="wsDualHttpBinding_IGreetingService" 
         clientBaseAddress="http://localhost:8088/clientCallbackUrl">
        </binding>
      </wsDualHttpBinding>
    </bindings>
I also had to specify the bindingConfiguration in endpoint to point to this.
<endpoint address="ws" binding="wsDualHttpBinding" 
contract="DuplexChannel.IGreetingService" 
bindingConfiguration="wsDualHttpBinding_IGreetingService"/>

But unfortunately specifying the clientBaseAddress in service configuration doesn’t take part in the WSDL. As a result clientBaseAddress won’t show up in the client side config. There is no negotiation happening during the runtime either.
So instead of providing the clientBaseAddress in the service side, create the proxy and config as usual and then provide the clientBaseAddress by modifying the client side configuration.
As a result, the client side configuration should typically be looking like this.
<configuration>
    <system.serviceModel>
        <bindings>
            <wsDualHttpBinding>
              <binding name="WSDualHttpBinding_IGreetingService"
                 clientBaseAddress="http://localhost:8088/clientCallbackUrl">
                <security mode="Message">
                  <message clientCredentialType="Windows" 
                          negotiateServiceCredential="true"
                      algorithmSuite="Default" />
                </security>
              </binding>
            </wsDualHttpBinding>
        </bindings>
        <client>
            <endpoint address="http://localhost:54927/GreetingService.svc/ws"
                 binding="wsDualHttpBinding" 
                 contract="GreetingService.IGreetingService"
                 bindingConfiguration="WSDualHttpBinding_IGreetingService"
                 name="WSDualHttpBinding_IGreetingService">
                <identity>
                    <userPrincipalName value="xxx\xxxx" />
                </identity>
            </endpoint>
        </client>
    </system.serviceModel>
</configuration>
Note: By default the Visual Studio would not be able to register even http://localhost:8088/clientCallbackUrl if it is used for the first time due to security constraints.
Refer to HTTP could not register URL for further detail.
An alternate solution to using netsh command is to run the Visual Studio itself in Administrator mode.
Article 2
From here on, I am going try to publish the exceptions/error messages I encounter during the programming and their corresponding resolution.
Exception
I wrote a self host in Visual Studio 2005 in Windows XP. It worked fine.
namespace CalculatorHost
{
    class Program
    {
        static void Main(string[] args)
        {
            ServiceHost host = new ServiceHost(typeof(CalculatorService), 
                new Uri[] { new Uri("http://localhost:8080/Calculator") });
 
            host.AddServiceEndpoint(typeof(ICalculatorService), 
                new BasicHttpBinding(), "");
 
            ServiceMetadataBehavior behavior = 
                new ServiceMetadataBehavior();
            behavior.HttpGetUrl = new 
                Uri("http://localhost:8080/CalculatorService/Meta");
            behavior.HttpGetEnabled = true;
 
            host.Description.Behaviors.Add(behavior);
 
            host.Open();
            Console.WriteLine("Calculator Service Started!!!"+
                "\nPress enter to stop the service");
            Console.ReadLine();
            host.Close();
        }
    }
}
 
I tried to execute the same program in Visual Studio 2010 in Windows 7. But it gave the following exception.
HTTP could not register URL http://+:8080/CalculatorService/Meta/. Your process does not have access rights to this namespace (see http://go.microsoft.com/fwlink/?LinkId=70353 for details).
Note: I received the same exception for http://localhost:8080/Calculator as well.
Solution
The exception itself has offered helping hands on how to register Http Namespace by saying(seehttp://go.microsoft.com/fwlink/?LinkId=70353 for details).
It takes us to the Microsoft’s title “Configuring HTTP and HTTPS”. The exception above resolved by following the solution under “Configuring Namespace Reservations”.
I ran the following command under the .Net Command Prompt.
C:\Program Files (x86)\Microsoft Visual Studio 10.0\VC>netsh http add urlacl url
Url reservation add failed, Error: 5
The requested operation requires elevation (Run as administrator).
I didn’t get through it yet, because by default the .Net command prompt doesn’t have access to register the Http Namespaces.
I reran the .Net command prompt in Administrator mode (Right Click the .Net Command Prompt in Start Menu, and select Run as Administrator).
The same command worked well in Administrator mode.
C:\Windows\system32>netsh http add urlacl url=http://+:8080/CalculatorService/Me
ta/ user=\Everyone
URL reservation successfully added
Another simple alternate to using netsh http command is to run the Visual Studio itself in Administrator mode.
Note: netsh is useful for a verity of work. Refer the following pages for more detail.

Wednesday, September 5, 2012

Understanding the error message: “Login failed for user ''. The user is not associated with a trusted SQL Server connection.”

Reference URL 


Please check the Article content:

Understanding the error message: “Login failed for user ''. The user is not associated with a trusted SQL Server connection.”
This exact Login Failed error, with the empty string for the user name, has two unrelated classes of causes, one of which has already been blogged about here:http://blogs.msdn.com/sql_protocols/archive/2005/09/28/474698.aspx.  In addition to an extra space in the connection string, the other class of causes for this error message is an inability to resolve the Windows account trying to connect to SQL Server.  This list is not intended to be exhaustive, but here are several known root causes for this error message. 
1)      If this error message occurs every time in an application using Windows Authentication, and the client and the SQL Server instance are on separate machines, then ensure that the account which is being used to access SQL Server is a domain account.  If the account being used is a local account on the client machine, then this error message will occur because the SQL Server machine and the Domain Controller cannot recognize a local account on a different machine.  The next step for this is to create a domain account, give it the appropriate access rights to SQL Server, and then use that domain account to run the client application.  Note that this case also includes the special accounts “NT AUTHORITY\LOCAL SERVICE” and “NT AUTHORITY\NETWORK SERVICE” trying to connect to a remote SQL Server, when authentication uses NTLM rather than Kerberos.
One very common case where this can occur is when creating web applications with SQL Server and IIS; often, the web page will work during development, then errors occur with this message after deploying the web site. This occurs because the developer’s account has access to SQL Server, but the account IIS runs as does not have access.  To fix this specific problem, refer to this kb article about impersonating a domain user in ASP.NET: http://support.microsoft.com/kb/306158
2)      Similar to above: this error message can appear if the user logging in is a domain account from a different, untrusted domain from the SQL Server’s domain.  The next step for this is either to move the client machine into the same domain as the SQL Server and set it up to use a domain account, or to set up mutual trust between the domains.  Setting up mutual trust is a complicated procedure and should be done with a great deal of care and due security considerations.
3)      This error message can appear immediately after a password change for the user account attempting to login.  This occurs because of caching of the client user’s credentials.  The next step here is to log out the application user with the old password, and re-login with the new password before running the application.
4)      If this error message only appears sporadically in an application using Windows Authentication, it may result because the SQL Server cannot contact the Domain Controller to validate the user.  This may be caused by high network load stressing the hardware, or to a faulty piece of networking equipment.  The next step here is to troubleshoot the network hardware between the SQL Server and the Domain Controller by taking network traces and replacing network hardware as necessary.
5)      This error message can appear consistently for local connections using trusted authentication, when SQL Server’s SPN is not interpreted by SSPI as belonging to the local machine.  This can be caused either by a misconfiguration of DNS, or by a machine having multiple names.  If your machine has multiple names, try to work around the need for multiple names and give it a unique name.  If the machine just has one name, then check your DNS configuration.

Wednesday, August 22, 2012

Throughput and response time

"Throughput vs Responsiveness" is best described in following article.
http://www.markj.net/throughput-and-response-time/

I am coping the same to here if in case the above site is not accessible..


What does ‘performance’ mean? Software performance is mostly about how fast the software goes and how much work it can handle. To discuss performance we need more accurate terms than ‘speed’. The two most important concepts are:
  • Response time – how quickly the system responds to request
  • Throughput – how much work can it do in some period of time
Response time is a measure of how quickly the system responds to a request for it to do something. Put another way, response time is how long it takes before it finishes what you told it to do. Response time is really important for any software that has real people sitting there interacting with it, eg a web application like Ebay. Users want the next page to come back quickly when they click on stuff. Response time for interactive software is often measured in seconds.
Throughput is a measure of how much work the system can do in a given period of time – eg if in one minute my mp3 software can encode 6 songs from a CD, then its throughput is 6 songs per minute. Throughput is really important to software that has to process a lot of data in some way, eg the electric company generating all the electricity bills for its millions of customers. Throughput is also critical for interactive software that has many users, eg how many web pages can Ebay serve up every second.
Response time and throughput are usually not independent of each other. If you are developing software you often have to trade one for the other in your architecture choices. Often times you can make a choice that will increase throughput by a large %, but it makes your response times increase a little (typically when you use request queues in your system). In that case, should you say that the software is faster because it does more work, or slower because it doesn’t react as fast? Both are true, so when you talk about performance it is confusing to talk about ‘speed’, you have to talk about response time and/or throughput.
Another side of throughput vs response time is who cares. If you are using ebay.com to buy a stuffed cat, you don’t care how many millions of pages ebay severed up while you were on the site (throughput), you only care about how fast your pages came back (response time). On the other hand, ebay management really care if their system can generate 1,000 or 10,000 page views a second (throughput), because they have tons of stuff they want everyone to keep everyone bidding on and they want to use the fewest servers possible to keep costs under control.

Wednesday, July 11, 2012

Drop Database Script: For Reference

EXEC msdb.dbo.sp_delete_database_backuphistory @database_name = N'DBName' GO USE [master] GO ALTER DATABASE [DBName] SET SINGLE_USER WITH ROLLBACK IMMEDIATE GO USE [master] GO DROP DATABASE [DBName] GO

Monday, July 2, 2012

Alphanumeric Algorithm

Please check the following url that describes best about Alphanumeric algorithm. The best part of this article is, author Dave Koelle has created this algorithm in various languages.


http://www.davekoelle.com/alphanum.html

For the future reference i have copied the c# code to my site. 
/*
 * The Alphanum Algorithm is an improved sorting algorithm for strings
 * containing numbers.  Instead of sorting numbers in ASCII order like
 * a standard sort, this algorithm sorts numbers in numeric order.
 *
 * The Alphanum Algorithm is discussed at http://www.DaveKoelle.com
 *
 * Based on the Java implementation of Dave Koelle's Alphanum algorithm.
 * Contributed by Jonathan Ruckwood 
 * 
 * Adapted by Dominik Hurnaus  to 
 *   - correctly sort words where one word starts with another word
 *   - have slightly better performance
 * 
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 *
 */
using System;
using System.Collections;
using System.Text;

/* 
 * Please compare against the latest Java version at http://www.DaveKoelle.com
 * to see the most recent modifications 
 */
namespace AlphanumComparator
{
    public class AlphanumComparator : IComparer
    {
        private enum ChunkType {Alphanumeric, Numeric};
        private bool InChunk(char ch, char otherCh)
        {
            ChunkType type = ChunkType.Alphanumeric;

            if (char.IsDigit(otherCh))
            {
                type = ChunkType.Numeric;
            }

            if ((type == ChunkType.Alphanumeric && char.IsDigit(ch))
                || (type == ChunkType.Numeric && !char.IsDigit(ch)))
            {
                return false;
            }

            return true;
        }

        public int Compare(object x, object y)
        {
            String s1 = x as string;
            String s2 = y as string;
            if (s1 == null || s2 == null)
            {
                return 0;
            }

            int thisMarker = 0, thisNumericChunk = 0;
            int thatMarker = 0, thatNumericChunk = 0;

            while ((thisMarker < s1.Length) || (thatMarker < s2.Length))
            {
                if (thisMarker >= s1.Length)
                {
                    return -1;
                }
                else if (thatMarker >= s2.Length)
                {
                    return 1;
                }
                char thisCh = s1[thisMarker];
                char thatCh = s2[thatMarker];

                StringBuilder thisChunk = new StringBuilder();
                StringBuilder thatChunk = new StringBuilder();

                while ((thisMarker < s1.Length) && (thisChunk.Length==0 ||InChunk(thisCh, thisChunk[0])))
                {
                    thisChunk.Append(thisCh);
                    thisMarker++;

                    if (thisMarker < s1.Length)
                    {
                        thisCh = s1[thisMarker];
                    }
                }

                while ((thatMarker < s2.Length) && (thatChunk.Length==0 ||InChunk(thatCh, thatChunk[0])))
                {
                    thatChunk.Append(thatCh);
                    thatMarker++;

                    if (thatMarker < s2.Length)
                    {
                        thatCh = s2[thatMarker];
                    }
                }

                int result = 0;
                // If both chunks contain numeric characters, sort them numerically
                if (char.IsDigit(thisChunk[0]) && char.IsDigit(thatChunk[0]))
                {
                    thisNumericChunk = Convert.ToInt32(thisChunk.ToString());
                    thatNumericChunk = Convert.ToInt32(thatChunk.ToString());

                    if (thisNumericChunk < thatNumericChunk)
                    {
                        result = -1;
                    }

                    if (thisNumericChunk > thatNumericChunk)
                    {
                        result = 1;
                    }
                }
                else
                {
                    result = thisChunk.ToString().CompareTo(thatChunk.ToString());
                }

                if (result != 0)
                {
                    return result;
                }
            }

            return 0;
        }
    }
}