Skip to main content

Posts

Showing posts from October, 2011

Single_user and Multi_user

It is often necessary to change the database to single user mode, especially if you are a DBA. A simple example would be to change the collation settings or any DB settings. The single user will allow only one  user ( usually DBA) to access the database. Hence it will be easy to make changes without the worry of deadlocks or any other type of contention for DB and also without affecting the users. It is very easy to change the database to Single user mode; in fact, it is just an execution of the script away. Use the script below to change the mode. ALTER  DATABASE  < >   SET SINGLE_USER    WITH  NO_WAIT The  NO_WAIT  clause will set it to single user mode as soon as you execute the query.  An alternate  to this is by using the  system  stored procedure  sp_dboption EXEC     SP_DBOPTION    << Data base  Name>>, ‘SINGLE USER’  ,False You need to however set the database  back to multi user mode for other users to use it. Without that, it won’t be access

Upgrading an ASP.NET MVC 3 Project to ASP.NET MVC 4

ASP.NET MVC 4 can be installed side by side with ASP.NET MVC 3 on the same computer, which gives you flexibility in choosing when to upgrade an ASP.NET MVC 3 application to ASP.NET MVC 4. The simplest way to upgrade is to create a new ASP.NET MVC 4 project and copy all the views, controllers, code, and content files from the existing MVC 3 project to the new project and then to update the assembly references in the new project to match the old project. If you have made changes to the Web.config file in the MVC 3 project, you must also merge those changes into the Web.config file in the MVC 4 project. To manually upgrade an existing ASP.NET MVC 3 application to version 4, do the following: In all Web.config files in the project (there is one in the root of the project, one in the Views folder, and one in the Views folder for each area in your project), replace every instance of the following text: System . Web . Mvc , Version = 3.0 . 0.0 System . Web . WebPages , Version

4 level Object Name in SQL Server

There are four levels in the naming convention for any SQL Server object [ServerName.[DatabaseName.[SchemaName.]]]ObjectName Schema Name (or Ownership) --the object created is assigned to a schema rather than an owner. Whereas an owner related to one particular login, a schema can now be shared across multiple logins, and one login can have rights to multiple schemas --For object not belonging to default schema state, use the schema name of your object. The Default Schema: dbo::::::::::::::::::::::::::::: --for user of a database MySchema(login name) a table my.table created will have a ownerqualified object name would be MySchema.MyTable. So to access this table we need to use the name MySchema.MyTable (as this is created by a user) --for database owner fred, a table created as myTable , ownerqualified object name would be dbo.MyTable. ****as dbo also happens to be the default owner, any user could just refer to the table as MyTable. --sa (sysadmin role)will always have f

Getting username and role in a database

--To get a list of all databases select name from master.dbo.sysdatabases Order by name -- To get a list of users and role name select b.name as USERName, c.name as RoleName from DatabaseName.dbo.sysmembers a join DatabaseName.dbo.sysusers b on a.memberuid = b.uid join DatabaseName.dbo.sysusers c on a.groupuid = c.uid -- list of username and their roles SELECT UserName, Max(CASE RoleName WHEN 'db_owner' THEN 'Yes' ELSE 'No' END) AS db_owner, Max(CASE RoleName WHEN 'db_accessadmin ' THEN 'Yes' ELSE 'No' END) AS db_accessadmin , Max(CASE RoleName WHEN 'db_securityadmin' THEN 'Yes' ELSE 'No' END) AS db_securityadmin, Max(CASE RoleName WHEN 'db_ddladmin' THEN 'Yes' ELSE 'No' END) AS db_ddladmin, Max(CASE RoleName WHEN 'db_datareader' THEN 'Yes' ELSE 'No' END) AS db_datareader, Max(CASE RoleName WHEN 'db_datawriter' THEN 'Yes

Windows in MSMS

Register a Server View - Registered Servers (Ctrl + Alt + G) will display the Registered Servers window Click on Local Server Groups to get the list of Registered servers To add a server to the list - right click and select 'New Server Registration' Enter the server name and authentication details and click on test. Save the server. If you have saved the credentials double clicking on the server name will connect to the machine automatically Object Explorer Right click on the server name and click on Object Explorer the window will be opened. Now you can access the database from here Error List window It displays all the errors encountered on that query page Template Explorer This is a very useful window. All the templates which may be useful to you are accessible here . SQL Server Profiler A very useful tool in SQL