Tuesday, December 31, 2013

ssrs 2005

doesn't have quick totals - boo

Wednesday, December 25, 2013

Code to color all panels and tabs in a windows form



  private static void setColor(Control parent,System.Drawing.Color color)
        {
            foreach (Control C in parent.Controls)
         {
             Debug.WriteLine(C.Name); 
                if (C.GetType() == typeof(TabPage)||
                 C.GetType() == typeof(Panel)||
                 C.GetType() == typeof(SplitterPanel)
                 )
                
             {C.BackColor = color;
             Debug.WriteLine("writing color");
                
             }
             if(C.Controls.Count > 0)    
                {
                 setColor(C, color);
            }
          }
        }

Debug.Writeline

only works if the debug symbol is declared

Simple copy dtabase script in sql server 2005

BACKUP DATABASE blah
  TO DISK = 'd:\blah.bak'

RESTORE DATABASE blah_blah
  FROM DISK = 'd:\blah.bak'
  WITH MOVE 'blah' TO 'd:\databases\blah_blah.mdf',
  MOVE 'blah_log' TO 'd:\databases\blah_blah.ldf'

Wednesday, December 11, 2013

TFS Bizarre behavior

checking in a file that was lined to a task made the task closed - very wierd

Tuesday, December 10, 2013

duration

in the app is in milliseconds ; in output is microseconds

team city and comments

it appears that team city removes /**/ comments and keeps -- comments in stored procedures

the requested operation requires elevation

when running ipconfig /flushdns

run as admin

Thursday, December 5, 2013

Wednesday, December 4, 2013

Unexpected Error creating debug information file

i had this while trying to compile a project that was attached to a process

Wednesday, November 27, 2013

Example of Singleton pattern

    public class sing
    {
        private static sing Sing;

        private sing()
        {

        }

        public int x;
        public int y;
        public static sing SING
        {
            get
            {
                if (Sing == null)
                {
                    Sing = new sing();
                }
                return Sing;
            }
        }

    }


static void Main(string[] args)
        {

            sing.SING.x = 7;

            Console.WriteLine(sing.SING.x.ToString());

Thursday, November 21, 2013

still getting excel save prompt with automation

tried these 2 ideas

  object misValue = System.Reflection.Missing.Value;
                        workBook.Saved = true;
                        workBook.Close(false, misValue, misValue);

Tuesday, November 19, 2013

This document is opened by another project

i was getting this message on a class - I had added a member class to the class and it was being picked up in only some locations - somehow there was a connection

my advice - close VS - even compiling solution did not help

Thursday, November 14, 2013

Tuesday, November 12, 2013

Monday, November 11, 2013

Dependency injection

here

if the pattern used creates the dependencies in properties but allows sets as follows:

#if DEBUG
            set { m_blah = value; }
#endif


I am not sure if this is true dependency injection

using random in sql for unique values

create table #tempo (id int unique identity, val varchar(100)  unique, other  varchar(1000))
insert into #tempo(val,other  )
select cast (cast(RAND() * 100000000 as int ) as varchar)    ,'fdgfggdfdfgdg'
union select cast(cast( RAND()* 100000000 as int) as varchar)   ,'fdfgdfdfgdg'
select * from #tempo
drop table #tempo

IISRESET vs Recycling Application Pools

here

Wednesday, November 6, 2013

Table types in Team City

create a script that drops the sp's that reference the table type - drop the table type
have this run before the sp's do

HTTP 304 - visibility

You will only see on the browsers network traffic- not Fiddler

Monday, November 4, 2013

How to get to dynamically loaded javascript in browser debugger

in IE if you run it once the script will be available in the source
all browsers - use "debugger"  keyword
all browsers - place breakpoint in static JS and f10 from there

force jquery not to use cache

$.ajax({url: "url", success: Callback, cache: false});


and avoid http 304!

Tuesday, October 29, 2013

Including JQuery manually

<script src="<%= Url.Content("~/Scripts/jquery-1.5.1.min.js") %>" type="text/javascript

Use NuGet

to install JQuery in a project where it isn't already installed

Monday, October 28, 2013

advantage of IE JS Debugger over chrome

putting breakpoints on anonymous code blocks

drop table statement

doesn't work on table variables

when I was sleeping

sql server added multiple values on insert thusly:
 DECLARE @tbl TABLE (
test VarChar(100) NOT NULL
);
insert into @tbl values('xzczxc'),('erter')
select * from @tbl


Difference between 'POST' and $.post

in this case the the token was properly posted

$.post(serviceURL, {Ids: ids,actionId: action.Id, __RequestVerificationToken: token },
             function (data) {


while this way

$.ajax(
      {
            url: serviceURL,
             type: 'POST',
              contentType: "application/json; charset=utf-8",
            data: {
                    Ids: ids,
                   actionId: action.Id,
               __RequestVerificationToken: token

it wasn't. No idea why.

Thursday, October 24, 2013

export registered servers in ssms

do not include user names and pswds - otherwise the file is encrypted and the export file wont work on another machine

Tuesday, October 22, 2013

mvc http 500 errors

check the passed parameters - the procedure will never be hit

Thursday, October 17, 2013

Monday, October 14, 2013

search in VS

ctrl-shft-f to get search in files

Friday, October 11, 2013

The remote server returned an error: NotFound

use fiddler

InvalidDataContractException: No set method for property

here 

Chrome clear cache

1. In chrome, open the chrome developer toolbar. (shortcut F12)
2. Click and hold the “Reload” button on the chrome. After a second you get the options as shown in the screen shot below.
3. Select the third option : “Empty Cache and Hard Reload”

Thursday, October 3, 2013

get schema of sp

select OBJECT_SCHEMA_NAME([object_id]),OBJECT_NAME(object_id)  from sys.sql_modules

Debugging in VS large solutions

never run "run"

instead , go to the main website and view in browser then attach the debugger to the port

otherwise all the symbols will have to load and life is too short

Wednesday, October 2, 2013

Monday, September 30, 2013

a few points about sql server execution plan


  • sql server will not use your order of joins if it thinks it can do it better. For example, if in your code a is joined to b and b to c but the index on a is enough to get the columns needed on c - it may join a to c.
  • the only thing for certain is logical reads, not physical
  • the determining factor for high % (for example , shown in sql sentry plan as red) is the amount of executions





Getting latest from Solution and getting latest from source control explorer are

different

Wednesday, September 18, 2013

Monday, September 16, 2013

The HTTP request is unauthorized with client authentication scheme 'Anonymous'. The authentication header received from the server was 'Negotiate'

in this case we were using wshttpbinding
this was happening with some kind of certificate issue. we changed the client service url to refer to the port and this issue stopped

Thursday, September 12, 2013

Like in sql profiler

is not sql's like - its an exact match

Wednesday, September 11, 2013

Wednesday, September 4, 2013

Wednesday, August 21, 2013

Nuget- an error occurred

run the vs with logging to see the error

devenv.exe /log "c:\log.xml"

Limit profile in sql server profiler

trace file properties-> column filters->edit filters -> like etc, exclude rows etc

Thursday, August 8, 2013

Fiddler is a lifesaver with silverlight problems


The imported project "C:\Program Files\MSBuild\Microsoft\Silverlight\v5.0\Microsoft.Silverlight.CSharp.targets" was not found

download Microsoft Silverlight 5 Tools and SDK

Silverlight securityexception








for cross-domain issues add these 2 files to the root of your website clientaccesspolicy.xml

<?xml version="1.0" encoding="utf-8"?>
<access-policy>
  <cross-domain-access>
    <policy>
      <allow-from http-request-headers="SOAPAction">
        <domain uri="*"/>
      </allow-from>
      <grant-to>
        <resource path="/" include-subpaths="true"/>
      </grant-to>
    </policy>
  </cross-domain-access>
</access-policy>

crossdomain.xml

<?xml version="1.0" ?>
<cross-domain-policy>
<allow-access-from domain="*" />
</cross-domain-policy>

of course ,based on security change the files above

Copy with Formatting on Notepad++


Autosizing in Silverlight

use textblock not label

Templates in Outlook

here

Wednesday, August 7, 2013

c# Action is just a delegate

for example

      public static void DoIt(int a, Action<int> act)
        {
            Console.WriteLine("$$$$$$$$$$$$$$$$$");
            act(a);
            Console.WriteLine("$$$$$$$$$$$$$$$$$");
        }

 is equivalent to:

        public delegate void action<T>(T item);
        public static void DoIt2(int a, action<int> act)
        {
            Console.WriteLine("$$$$$$$$$$$$$$$$$");
            act(a);
            Console.WriteLine("$$$$$$$$$$$$$$$$$");
        }

       
        static void Main(string[] args)
        {
           
            DoIt(56, write);
            DoIt(56, writeTwice);

            DoIt2(56, write);

            DoIt2(56, writeTwice);

Code refactoring

  • Techniques that allow for more abstraction
    • Encapsulate Field – force code to access the field with getter and setter methods
    • Generalize Type – create more general types to allow for more code sharing
    • Replace type-checking code with State/Strategy[6]
    • Replace conditional with polymorphism [7]
  • Techniques for breaking code apart into more logical pieces
    • Componentization breaks code down into reusable semantic units which present clear, well-defined, simple-to-use interfaces.
    • Extract Class moves part of the code from an existing class into a new class.
    • Extract Method, to turn part of a larger method into a new method. By breaking down code in smaller pieces, it is more easily understandable. This is also applicable to functions.
  • Techniques for improving names and location of code

from here 

Extension Methods


  • in order for the extension method to be visible - the method must be in a static class. If its in, lets say,the main of as console app, it will compile - you can reference it directly, but not from the instance .
  • extension methods only work on instances, not static classes 

Tuesday, August 6, 2013

Simple example of c# Action

  public static void write(int a)
        {
            Console.WriteLine(a); 
        }

        public static void writeTwice(int a)
        {
            Console.WriteLine(a);
            Console.WriteLine(a);
        }

        public static void DoIt(int a, Action<int> act)
        {
            Console.WriteLine("$$$$$$$$$$$$$$$$$");
            act(a);
            Console.WriteLine("$$$$$$$$$$$$$$$$$");
        }
       
        static void Main(string[] args)
        {
            DoIt(56, write);

            DoIt(56, writeTwice);

Using a for loop on a linked list

    LinkedList<int> ll = new LinkedList<int>(new int[] {2, 5, 8, 2, 3, 6 });
            for (LinkedListNode<int> node = ll.First; node != null; node = node.Next)
            {
                Console.WriteLine(node.Value);
            }


IEEE 754 Double Precision floating point woes


here

Examples of invariance in c#

  class Test <T>
    {
        public T  y { get; set; }

    }
         

  Test<string> r = new Test<string>();

  Test<object> r2 = r;

this fails

likewise

  public void consumeList(List<object> l)
        {

        }


consumeList(new List<object>(){"fgdg","ghffh"}); 
is OK  while
t.consumeList(new List<string>(){"fgdg","ghffh"});  
fails

Generic properties for non generic classes

are illegal

    class Test
    {
        public T  y<T> { get; set; }


    }

instead you need the following

    class Test <T>
    {
        public T  y { get; set; }

    }

[DataContract] = [Serializable]

    [DataContract]
    public class herby
    {
     [DataMember]
      public  int i {get;set;}
     [DataMember]
      public string s {get;set;}
    }

is equivalent to

    [Serializable]
    public struct herby
    {
        public int i;
        public string s;
    }

    

Easy way to test WCF and REST services - use WebServiceHost class

  static void Main(string[] args)
        {
            WebServiceHost host = new WebServiceHost(typeof(Service), new Uri("http://localhost:8000/"));
            try
            {
                ServiceEndpoint ep = host.AddServiceEndpoint(typeof(IService), new BasicHttpBinding(), "");
                host.Open();
                using (ChannelFactory<IService> cf = new ChannelFactory<IService>(new BasicHttpBinding(), "http://localhost:8000"))
                {
                   // cf.Endpoint.Behaviors.Add(new bas WebHttpBehavior());
                    IService channel = cf.CreateChannel();
                    herby h = channel.getHerby();
                    Console.WriteLine("   i: {0}", h.i );
                    Console.WriteLine("   s: {0}", h.s);
                    Console.WriteLine("");

                    Boris b = channel.getBoris();
                    Console.WriteLine("   i: {0}", h.i);
                    Console.WriteLine("   s: {0}", h.s);
                    Console.WriteLine("");
                }
                Console.WriteLine("Press <ENTER> to terminate");
                Console.ReadLine();
              
                host.Close();
            }
            catch (CommunicationException cex)
            {
                Console.WriteLine("An exception occurred: {0}", cex.Message);
                host.Abort();
            }
        }


empty values in WCF DataContract

could be caused by forgetting DataMember attribute

Some Basic SQL interview questions for .net developers


  • what is the difference between a union and a join?
  • if you have a simple table of people with amounts of money - how would you get the name of the 2nd highest owner?
  • how would you get the 2nd highest amount?
  • if you have a table with name company amount and you you want to have sums per company how would you filter companies with 0 and null amounts ? 
  • what is the difference between where and having?
  • what is the difference between exists and a join?
  • How would you create a database that needed to store a user name, password, and 2 phone numbers?
  • What are some of the ways you can ensure unique data in a table?
  • What is a CTE (common table expression) and when can it be used?
  •  What would be the first few things you would check to try to improve a SQL call that is taking a long time to run?



Visual Studio Reference issues

sometimes the using statement wont fail even though there is no reference

this happened to me with
using System.Runtime.Serialization;
which did not fail

Wednesday, July 31, 2013

Tuesday, July 30, 2013

Get IE to display JsonResult instead of prompt to download

return Json(bm, "text/html", JsonRequestBehavior.AllowGet);

Html.ValidationSummary always showing

added this to fix

   <style type ="text/css">
    .validation-summary-valid { display:none; }
    </style>

[ControllerAction] deprecated and illegal

use [NonAction] instead

Monday, July 29, 2013

Linq Datatable subset as a datatable

blah.Rows.Cast<DataRow>().Where(row => row.Field<int>("ID").Equals(i)).CopyToDataTable();

will return onle where id = i

inserting partial views

<% Html.RenderPartial("heh"); %>

Parser Error Message: The type 'System.Web.Mvc.ViewPage' is ambiguous

fixed it thus:
<runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35"/>
        <bindingRedirect oldVersion="2.0.0.0" newVersion="4.0.0.0"/>
      </dependentAssembly>
    </assemblyBinding>

  </runtime>

also, look here.

New Razor @ Syntax

here

New Syntax for embedded html encoded text

<%:

Difference Between ViewBag & ViewData


Controller
[HttpGet]
        public ActionResult HerbyList()
        {
            HerbyModel hm = new HerbyModel();
            ViewData["HerbyList"] = hm.Herb;
            ViewBag.HerbyList = hm.Herb;
            return View();
        }

 View

//   this.GridView1.DataSource = (DataTable)ViewData["HerbyList"];
            this.GridView1.DataSource = ViewBag.HerbyList;

            this.GridView1.DataBind();  

Restricting MVC to Particular HTTP Verbs

[HttpGet]
        public ActionResult HerbyList()

        {

This is a perfect place to use Fiddler's composer - to change a regular page from a get to a post to test

also the older syntax:

[AcceptVerbs(HttpVerbs.Post)] 


an important use for this is one view for a get with default info and the same view for post to get the updated values  - example:

    [HttpGet]
        public ActionResult Update()
        {
            BookModel bm = new BookModel();
            bm.Author = "default";
            bm.Title = "default";

            return View(bm);
        }

        [HttpPost]
        public ActionResult Update(BookModel b)
        {
            return View(b);
        }