dotnet thoughts 

a dotnet developer's technical blog

Changing authentication mode and enabling sa using osql

Changing authentication mode and enabling sa using osql Few days back, I tried to install SQL Server Management studio express in my machine, because of some strange reasons, it is getting rollbacked everytime. I don’t know why I am getting that error. Then for some development purpose I have to use sa, or sql authentication in SQL 2005 instead of Windows. If I do have SQL Server Management studio, it is pretty easy job. But using osql and registery settings we can achive the same.

  1. Changing SQL Server authentication mode. Note: Backup registry before making any changes.
    1. Open Registry editor using RegEdit command.
    2. Goto the key HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SQL Server\MSSQL.x\MSSQLServer, locate a subkey with name “LoginMode”.
    3. If LoginMode subkey is 1, then the SQL Server is confingured to Window authentication, and if it is 2 then it is Mixed mode authentication.
    4. Go to services and stop all the sql server related services, before making the change.
    5. Double click on the LoginMode subkey, in the DWORD Editor dialog, set the value as 2.
    6. Restart all the SQL related services

    This procedure will change the authentication mode to mixed mode, so that we can use “sa” user for login. But by default “sa” may not be enabled.

  2. Enabling sa account
    1. Go to command promprt type “osql -S localhost\SqlExpress -E”
    2. This will authenticate you with windows authentication, to the local sql express. You will get 1> sign for accepting the Sql commands
    3. You need to give sa a stong password because of security reasons. You can do this by this was “sp_password @old = null, @new = ‘complexpwd’, @loginame =’sa’; ” and type “go”
    4. Type “ALTER LOGIN sa ENABLE” and “GO”, will enable the sa account.
    5. Type quit, and try login using sa, like this “osql -S localhost\SqlExpress -U sa -P mypassword”. If everything worked fine, you will get a prompt 1>

You can also get information on these link from Microsoft.

  1. How to verify and change the system administrator password in MSDE or SQL Server 2005 Express Edition
  2. How to: Change Server Authentication Mode

Visual studio 2008 command line switchs

Some times it requires use Visual studio in command line. Here is a few I got from Visual studio 2008.

Use:

devenv  [solutionfile | projectfile | anyfile.ext]  [switches]

The first argument for devenv is usually a solution file or project file. You can also use any other file as the first argument if you want to have the file open automatically in an editor. When you enter a project file, the IDE looks for an .sln file with the same base name as the project file in the parent directory for the project file. If no such .sln file exists, then the IDE looks for a single .sln file that references the project. If no such single .sln file exists, then the IDE creates an unsaved solution with a default .sln file name that has the same base name as the project file.

Command line builds:

devenv solutionfile.sln /build [ solutionconfig ] [ /project projectnameorfile [ /projectconfig name ] ]

Available command line switches:

/Build

Builds the solution or project with the specified solution  configuration. For example “Debug”. If multiple platforms  are possible, the configuration name must be enclosed in quotes and contain platform name. For example: “Debug|Win32″.

/Clean

Deletes build outputs.

/Command

Starts the IDE and executes the command.

/Deploy

Builds and then deploys the specified build configuration.

/Edit

Opens the specified files in a running instance of this application. If there are no running instances, it will  start a new instance with a simplified window layout.

/LCID

Sets the default language in the IDE for the UI.

/Log

Logs IDE activity to the specified file for troubleshooting.

/NoVSIP

Disables the VSIP developer’s license key for VSIP testing.

/Out

Appends the build log to a specified file.

/Project

Specifies the project to build, clean, or deploy. Must be used with /Build, /Rebuild, /Clean, or /Deploy.

/ProjectConfig

Overrides the project configuration specified in the solution  configuration. For example “Debug”. If multiple platforms are possible, the configuration name must be enclosed in quotes and contain platform name. For example: “Debug|Win32″. Must be used with /Project.

/Rebuild

Cleans and then builds the solution or project with the specified configuration.

/ResetAddin

Removes commands and command UI associated with the specified Add-in.

/ResetSettings

Restores the IDE’s default settings, optionally resets to the specified VSSettings file.

/ResetSkipPkgs

Clears all SkipLoading tags added to VSPackages.

/Run

Compiles and runs the specified solution.

/RunExit

Compiles and runs the specified solution then closes the IDE.

/SafeMode

Launches the IDE in safe mode loading minimal windows.

/Upgrade

Upgrades the project or the solution and all projects in it. A backup of these files will be created as appropriate.  Please  see Help on ‘Visual Studio Conversion Wizard’ for more information on the backup process.

 

Product-specific switches:

/debugexe

Open the specified executable to be debugged. The remainder of the command line is passed to this executable as its arguments.

/useenv

Use PATH, INCLUDE, LIBPATH, and LIB environment variables instead of IDE paths for VC++ builds.

 

To attach the debugger from the command line, use: VsJITDebugger.exe -p <pid>

Happy coding :)

This is an Update: I got a comment from Ced saying , these things are not working with VS C# Express. Then today I got a change to do some R&amp;D on it and I found, it will not, because VS Express not supports all the command line arguments VS Professional or Standard supports. And I am also including the switchs for Express edition for Visual basic.

Use:

vbexpress  [solutionfile | projectfile | anyfile.ext]  [switches]

The first argument for vbexpress is usually a solution file or project file. You can also use any other file as the first argument if you want to have the file open automatically in an editor. When you enter a project file, the IDE looks for an .sln file with the same base name as the project file in the parent directory for the project file. If no such .sln file exists, then the IDE looks for a single .sln file that references the project. If no such single.sln file exists, then the IDE creates an unsaved solution with a default .sln file name that has the same base name as the project file.

Command line builds:

vbexpress solutionfile.sln /build [ solutionconfig ] [ /project projectnameorfile [ /projectconfig name ] ]

Command line switches:

/Log

Logs IDE activity to the specified file for troubleshooting.

/ResetSettings

Restores the IDE’s default settings, optionally resets to  the specified VSSettings file.

/SafeMode

Launches the IDE in safe mode loading minimal windows.


To attach the debugger from the command line, use:

VsJITDebugger.exe -p <pid>

Thanks Ced for your valueable comments.

Kerala Microsoft Users Group (K-MUG) Launch on 25th Oct 2008

Kerala Microsoft Users Group (K-MUG) Launch on 25th Oct 2008

Kerala Microsoft Users Group (K-MUG) Launch on 25th Oct 2008

Kerala Microsoft Users Group (K-MUG) Launch on 25th Oct 2008


Please visit K-MUG site for more details.

Control focus with Postback

While working with ASP.Net update panel control, the Tab focus will make some problems. Here is a simple solution for that, you can use the Script Manager class to set focus to a specific control.

ScriptManager1.SetFocus(Control);	//You can either use the control or the clientID of the control.

And if you are using Master Pages and placing the script manager in the master page, you can use the following code to get the script manager class.

ScriptManager ScriptManager1 = ScriptManager.GetCurrent(this.Page)	//Getting the script manager class of the current page.