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

Tuesday, July 17, 2012

error from asp.net 3.0 to asp.net 4.0

Error:
The type 'System.Web.Mvc.ModelClientValidationRule' exists in both 'd:\Program Files\Microsoft ASP.NET\ASP.NET Web Pages\v2.0\Assemblies\System.Web.WebPages.dll' and 'd:\Program Files\Microsoft ASP.NET\ASP.NET MVC 3\Assemblies\System.Web.Mvc.dll

Resolution:
Issue resolved as per http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253815

Methods (Copied from http://www.asp.net/whitepapers/mvc4-release-notes#_Toc303253815 for reference):



  1. In the root Web.config file, add a new <appSettings> entry with the key webPages:Version and the value 1.0.0.0.
  2. <appSettings>
        <add key="webpages:Version" value="1.0.0.0"/>
        <add key="ClientValidationEnabled" value="true"/>
        <add key="UnobtrusiveJavaScriptEnabled" value="true"/>
    </appSettings>
  3. In Solution Explorer, right-click the project name and then select Unload Project. Then right-click the name again and select Edit ProjectName.csproj.
  4. Locate the following assembly references:
    <Reference Include="System.Web.WebPages"/> <Reference Include="System.Web.Helpers" />
    Replace them with the following:
    <Reference Include="System.Web.WebPages, Version=1.0.0.0,
    Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL "/> <Reference Include="System.Web.Helpers, Version=1.0.0.0,
    Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL" />
  5. Save the changes, close the project (.csproj) file you were editing, and then right-click the project and select Reload.


Friday, June 29, 2012

Creating a kanban board with javascript

At SyneITY we follow the lean agile development methodology and to aid in our development we needed a kanban board and thought why not develop it using javascript, jquery and knockoutjs.

As usual, we are just starting out with a basic version and here is a mockup of what we were trying to achieve in the first iteration
Technologies we will be using:

  • Javascript
  • Jquery
  • Knockoutjs
  • Ajax

Wednesday, June 27, 2012

PHP Call to undefined function curl_init()

while working on php in windows using VS.PHP i came across this exception:
"Call to undefined function curl_init()"
Earlier when i had come across this exception, we had used this answer on stackoverflow to resolve this issue.
However the next time, on another machine, this method was not solving the issue. On analysis this was found out to be an issue of using VS.php which overwrites the php.ini file everytime it runs. So using the video at this link i just put the ini path in the visual studio debug and viola, the issue was resolved.

Friday, June 22, 2012

Learning to use MOQ


MOQ
No i am not mocking you!!. MOQ is a mocking framework for .net and can be downloaded here.

What is a mocking framework?
It is basically a small piece of software that simulates the behavior of an interface, it is generally used for creating unit tests.

Confused??? let us just visualise a problem. let us visualise it as if you encountered it.
A Story to start using MOQ
You have a requirement to design a code generation application, for which you will be using some xml files with data required to generate the code. Now you get into work, do a lot of RND, work your brain day in and out and finish the code generation.

To test this out you write over 200 xml files and run your code, the code generation just takes 10 mins. Wow great, an entire application in 10 mins, Your team lead is impressed, he calls out for your manager, he comes over take a look and says, "Hey the application looks great but you have  forgotten to put the Billing address for the customer". You smile and say "Just a minute" and while the manager is there you make a slight change in the xml file and click generate. Voila in another 10 minutes, the issue is fixed. The manager is head over heels and you are sure of your next hike. 

Next day the manager calls you into the room and says "Man you are great!! and that work is so good that i am going to use it in my next meeting with the client. So get ready for the trip."

You are excited, tell your friends about it, make purchases for the trip and the next moment you are sitting with your manager in the flight. The next day at the client site, you and your manager stride up to the clients office. The client invites you inside, the manager introduces himself and then says "Hey Bill, this is John, the most talented developer in my company and we are here to solve your problems and that too in real time". 

You feel your head swelling with pride and you are quickly in the clouds though not the azure ones...

Your manager then starts the demo of the application, the client is impressed, then suddenly he squints and then roars "Hey don't you know english? Customer is spelled "CUSTOMER" not "CSUTOMER". You curse him  in your mind, "hey that is a typing error, why the hell doesn't he understand". Your manager soothes the customer and says "Hey that is a normal typing error, give me 10 minutes" and your manager glances at you. You quickly open a xml file make the necessary changes and click generate, 10 minutes down the lane, the generation screen closes, your manager wipes off the hint of sweat forming on his head and says "Bill, it is ready". The client is impressed, "Good finally you seem to have learnt programming".

The demo is then again in progress, yet again as usual the client gets hold of another issue, you smile, tweak your xml files and the demo continues. After 3-4 cycles of this same thing, you start noticing that the smile of your manager is slowly changing into a frown, and then Bill gets up and says "Guys! do one thing, will you just run over the application, make the required fixes and then get back, i just remembered i have a meeting with my boss.". 

You and your manager slowly packup your laptops and then go back to room, on the way back, you have lunch. Your manager doesn't talk much, you too feel the pressure. After lunch while trudging back to the room, your manager says, "Hmmm... That was a bad meeting, i thought we would close it for once and 
all. now i dont know how long it is going to take, John, can we do one thing, can we make this code generation faster?", you stop in your tracks and think, "In 10 minutes we are doing what 5-6 people did in 3 months time that too with more bugs & issues, and now he thinks 10 minutes is too much... ", you think for sometime and say "Maybe there is a way, i will check and see what can be done". Then you both re-enter into silence and go to your room.

You go, open the fridge, grab a can of beer. Still you cannot take your mind off things. to cool off a shower should be good, you quickly go in and take a shower, now beneath the shower you start thinking about the issue, suddenly everything falls into place, Why generate all the 200 files, why not just generate the files that are modified? yes why not. Looking back, now it looks silly, you had been such a stupid idiot. You run into your room, take the laptop and begin coding..... 

Saturday, June 2, 2012

Regular Expression to get the attribute value from html string


public static string ExtractAttributeValueFromHtmlElement(string elementOuterHtml, string attributeName)
        {
            Match m;
            string HRefPattern = "title\\s*=\\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))";
 
            m = Regex.Match(elementOuterHtml, HRefPattern,
                            RegexOptions.IgnoreCase | RegexOptions.Compiled);
            if (!m.Success)
            {
                return null;
            }
            return m.Groups[1].ToString();                            
        }


pattern = style=\s*(?:\"(?<1>[^\"]*)\"|(?<1>\\S+))
input   = <td style="width:100px;height:100px;">Pramod</td>
result  = 
             style="width:100px;height:100px;"
             width:100px;height:100px;

Wednesday, February 29, 2012

Tuesday, February 14, 2012

Sql Server Shrink Log file

 

For a business Intelligence application, we used a sql server 2008 database for consolidating data from different sources, since data was imported, we didn’t need backup facility, so the database was kept in Simple Logged Mode.

In this blog we will see how to shrink the log files for a simple logged database.

IMPORTANT : Use this only for Simple Logged Databases

Use [DatabaseToShrink]-- Replace this with your simple logged database

Declare @FileId Int
select @FileId = FILE_ID from sys.database_files Where type_desc = 'LOG'

DBCC ShrinkFile(@FileId, 1)

select * from sys.database_files

Monday, February 6, 2012

Html content in RDLC Microsoft Reporting

 

We have been using microsoft reporting for generating itineraries, hotel vouchers etc in TourMast, the tour operator software. In this post i will explain how we display html content in some places:

Step 1:

Select the placeholder,

image
Right click and then select PlaceHolder Properties, you will get the following screen where you must select “HTML-Intepret HTML Tags as styles” in the Markup Type section

image
Reference:

http://stackoverflow.com/questions/3786884/visual-studio-2010-rdlc-support-for-html

Friday, January 27, 2012

Prevent duplicate rows using unique index

create table test(id int identity(1,1), name varchar(10))create
insert
unique index ix_test on test(name) with IGNORE_DUP_KEY into test(name)values('ppv')select * from test

Friday, January 6, 2012

Reenable sql server index

SELECT
'ALTER INDEX ' + I.name + ' ON ' + T.name + ' REBUILD ' FROM SYS.indexes I INNER JOIN SYS.tables T ON I.object_id = T.object_idWHERE I.name LIKE 'IX%'