Friday, May 19, 2017

Sql query to find all database with users in a dbserver



DECLARE @DBuser_sql VARCHAR(4000)
DECLARE @DBuser_table TABLE (DBName VARCHAR(200), UserName VARCHAR(250), LoginType VARCHAR(500), AssociatedRole VARCHAR(200))
SET @DBuser_sql='SELECT ''?'' AS DBName,a.name AS Name,a.type_desc AS LoginType,USER_NAME(b.role_principal_id) AS AssociatedRole FROM ?.sys.database_principals a
LEFT OUTER JOIN ?.sys.database_role_members b ON a.principal_id=b.member_principal_id
WHERE a.sid NOT IN (0x01,0x00) AND a.sid IS NOT NULL AND a.type NOT IN (''C'') AND a.is_fixed_role <> 1 AND a.name NOT LIKE ''##%'' AND ''?'' NOT IN (''master'',''msdb'',''model'',''tempdb'') ORDER BY Name'
INSERT @DBuser_table
EXEC sp_MSforeachdb @command1=@dbuser_sql
SELECT * FROM @DBuser_table ORDER BY DBName 

Thursday, May 18, 2017

SQL Query to find database size of all databases in server

In some situations we might need to find the sizes of all databases in the server. In case we dont have masterfile access we can use the following query:


DECLARE @DBsize_sql VARCHAR(4000)
DECLARE @DBsize_table TABLE (DBName VARCHAR(200), DbFileName VARCHAR(250), CurrentSizeMB numeric(18,4), FreeSpaceMB numeric(18,4))
SET @DBsize_sql='Use ? SELECT DB_NAME() AS DbName, Name AS DbFileName, size/128.0 AS CurrentSizeMB,
size/128.0 - CAST(FILEPROPERTY(name, ''SpaceUsed'') AS INT)/128.0 AS FreeSpaceMB
FROM sys.database_files'
INSERT @DBsize_table
EXEC sp_MSforeachdb @command1=@DBsize_sql
SELECT * FROM @DBsize_table
ORDER BY DbFileName


Sunday, March 27, 2016

404 error for .woff font file in asp.net

When you use font awesome in asp.net, you get the 404 file not found error for the font files.

Error:

Failed to load resource: the server responded with a status of 404 (Not Found).
http://localhost/web-led/font-awesome/fonts/fontawesome-webfont.woff2?v=4.3.0



Fix:
This can be fixed by adding the mime type in the web config, under the system.webServer section

<system.webServer>
    <staticContent>
      <remove fileExtension=".woff" />
      <mimeMap fileExtension=".woff" mimeType="application/x-font-woff" />
      <remove fileExtension=".woff2" />
      <mimeMap fileExtension=".woff2" mimeType="application/x-font-woff2" />
    </staticContent>    
</system.webServer>


As mentioned by Deepak in the comments, if you have access to the iis you can easily set it from IIS itself. 

Monday, March 21, 2016

Identify Anonymous Users in Asp.net

Identify anonymous users in asp.net

The first thing when we read about identifying anonymous users in asp.net mvc is "Why do we need to identify anonymous users?". Well the same thought had crossed my mind, but then when developing an e-commerce application, we needed anonymous users to add items to the shopping cart without logging in. We also needed these items to be loaded into the shopping cart, the next time they visited.

How do we do this?

Asp.net provides a guid accessed through the Request.AnonymousId property with which the user can be identified.
  1. Enable anonymous Identification

    Anonymous Identification need to be enabled, else Request.AnonymousId will be null.
    <configuration>
        <system.web>
          <anonymousIdentification enabled="true"/>
        </system.web>
      </configuration>
  2. Access the Anonymous Id

    Anonymous Id can be accessed through Request.AnonymousID property.

Hope this helps someone.

Tuesday, August 25, 2015

Resizing virtual box storage

Microsoft Windows [Version 10.0.10240]
(c) 2015 Microsoft Corporation. All rights reserved.

C:\Users\user>cd C:\Program Files\Oracle\VirtualBox

C:\Program Files\Oracle\VirtualBox>vboxmanage modifyhd "C:\Users\user\VirtualBox VMs\Design\Design.vdi" --resize 81920
0%...
Progress state: VBOX_E_NOT_SUPPORTED
VBoxManage.exe: error: Resize hard disk operation for this format is not implemented yet!

C:\Program Files\Oracle\VirtualBox>vboxmanage clonehd "C:\Users\user\VirtualBox VMs\Design\Design.vdi" "C:\users\user\virtualbox vms\design\design_cl.vdi" --format vdi
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%
Clone hard disk created in format 'vdi'. UUID: e883d1c3-02a1-43da-97c4-522c1b4be8eb

C:\Program Files\Oracle\VirtualBox>vboxmanage modifyhd "C:\Users\user\VirtualBox VMs\Design\Design_cl.vdi" --resize 81920
0%...10%...20%...30%...40%...50%...60%...70%...80%...90%...100%

C:\Program Files\Oracle\VirtualBox>

Monday, October 6, 2014

Enabling Migrations in Entity Framework to update the database programatically

Migrations

Implementing migrations in entity framework

  • Open the Package Manager Console (Tools -> Library Package Manager -> Package Manager Console)
  • Select the project where the entity framework DataContext is contained and then in the console type Enable-Migrations
  • use the following code to update the migrations
  • Now a call to the migrate method on the migrator will result in the database being updated automatically to the current version

Thursday, May 9, 2013

The Web server is configured to not list the contents of this directory. IIS 7.5 asp.net mvc

After adding an app in iis, and running it came across the following issue.

HTTP Error 403.14 - Forbidden

The Web server is configured to not list the contents of this directory.


fixed it using this post

Microsoft Windows [Version 6.1.7601]
Copyright (c) 2009 Microsoft Corporation.  All rights reserved.

C:\Windows\system32>cd C:\Windows\Microsoft.NET\Framework\v4.0.30319

C:\Windows\Microsoft.NET\Framework\v4.0.30319>aspnet_regiis -i
Microsoft (R) ASP.NET RegIIS version 4.0.30319.17929
Administration utility to install and uninstall ASP.NET on the local machine.
Copyright (C) Microsoft Corporation.  All rights reserved.
Start installing ASP.NET (4.0.30319.17929).
....................
Finished installing ASP.NET (4.0.30319.17929).

C:\Windows\Microsoft.NET\Framework\v4.0.30319>


another issue while logging in

solved with http://www.aspdotnet-suresh.com/2011/05/systemdatasqlclientsqlexception-login.html