10/08/2011

SQL Server Reporting Services – Insufficient Rights Error

Ref:

Introduction
At times when we successfully deploy the reports to the report server and try to view them through report manager we may encounter am insufficient rights error. This article focuses on resolving that error.
Solution
After deploying the reports to the report server we can view them in the Report Manager web app provided by Microsoft for managing, delivering and applying the security to deployed reports. Generally the path to the report server is http://localhost/ReportServer if it is a default instance or http://localhost/ReportServer_InstanceName  for a named instance. Similarly the report manager can be viewed at http://localhost/Reports for the default instance and http://localhost/Reports_InstanceName for the named instance.
By default the built-in Administrators group has permission on the report server to access all the reports and the data sources deployed on the report server. If you are in the Administrators group you may not come across the following error while viewing the reports
The permissions granted to user ‘domain\username’ are insufficient for performing this operation. (rsAccessDenied)
But if you are a domain user (which in most cases we are). you will have to follow the below steps to resolve the error.
1. Right-click on the Internet Explorer icon and select on Run as administrator.
SS_SEC2.jpg
2.  Type the report manager’s URL in my case http://localhost/reports
3. The report manager window opens where you can see various icons and links. Go to site settings link in the report manager.
SS_SEC3.jpg
4. Click on Security.
SS_SEC4.jpg
5. Click on New Role Assignment and add the Domain\user and depending upon the role of the user in the organization assign them the appropriate role. You can either assign the role of System Administrator or System User both have different rights. In this example I will be providing the user with the role of System Administrator.  Click Ok.
SS_SEC5.jpg
6. You will see that the user has been added to the role specified. Click on Home button.
SS_SEC6.jpg
7. Go to the Folder Settings on the Home page.
SS_SEC7.jpg
8. Click on New Role Assignment and add the Domain\user and depending upon the role of the user in the organization assign them the appropriate role. You can either assign the role of the Content Manager who can delete, modify and manage all the content on the report server or Browser who can view the reports and subscriber depending upon your need. In this example I will assign the Content Manager role.
SS_SEC8.jpg
9. You will then see the user added to the Folder Setting.
SS_SEC9.jpg
10. Close the browser which was currently running into the Administrator mode.
11. Now you can open the report manager in my case  using http://localhost/reports

Using "GO" to run an sql batch many times

CREATE TABLE #tmp(
    DATA NVarCHAR(100)
)
GO

INSERT #tmp ( DATA ) VALUES  ( 'Ha ha')
GO 100

SELECT * FROM #tmp AS t

DROP TABLE #tmp        
GO

What Great .NET Developers Ought To Know - Part IV

Ref:  Scott Hanselman


Senior Developers/Architects (Part II)


  • Does JITting occur per-assembly or per-method? How does this affect the working set?
A: Per-method. Since methods which are not called are not compiled at all, this reduces the working set.
  • Contrast the use of an abstract base class against an interface? 
A: If you anticipate creating multiple versions of your component, create an abstract class. Abstract classes provide a simple and easy way to version your components. By updating the base class, all inheriting classes are automatically updated with the change. Interfaces, on the other hand, cannot be changed once created. If a new version of an interface is required, you must create a whole new interface. 

If the functionality you are creating will be useful across a wide range of disparate objects, use an interface. Abstract classes should be used primarily for objects that are closely related, whereas interfaces are best suited for providing common functionality to unrelated classes.

If you are designing small, concise bits of functionality, use interfaces. If you are designing large functional units, use an abstract class.

If you want to provide common, implemented functionality among all implementations of your component, use an abstract class. Abstract classes allow you to partially implement your class, whereas interfaces contain no implementation for any members.

For more info: http://sendhil.spaces.live.com/blog/cns!30862CF919BD131A!576.entry
  • What is the difference between a.Equals(b) and a == b?
A: Cannot be answered unless you have the variable declarations for a and b.

The default implemenation for Equals on object checks for references or identity.

There is no default implementation for ‘==’ on value types.

The default implementation for ‘==’ on reference types checks for idenity or memory references

  • In the context of a comparison, what is object identity versus object equivalence?
A: Identity comparison: check if both the instances point to the same memory address.

Equivalence: two instances are considered equal if their values represented by them are equal, they can point to different memory locations. For example:
“Person p1 = new Person();p1.age = 25;Person p2 = new Person();p2.age = 25;”

Identity comparison of p1 and p2 should return false whereas equivalence should return true.
  • How would one do a deep copy in .NET?
A: Serialize / DeSerialize is an option, but it has a performance impact and required all the objects to be serializable.

ICloneable is another.

  • Explain current thinking around IClonable.
A: Because the interface contract does not specify the type of clone performed, different classes have different implementations. A consumer cannot rely on ICloneable to let them know whether an object is deep-cloned or not. May be I would use something like ICloneableEx with ShallowCopy and DeepCopy as members.
  • What is boxing?
A: Boxing is the mechanism by which a value type is converted to a reference type.  
For more info: http://sendhil.spaces.live.com/blog/cns!30862CF919BD131A!349.entry
  • Is string a value type or a reference type?
A: String is a reference type. But being immutable it gives the illusion of a value type.
  • What is the significance of the "PropertySpecified" pattern used by the XmlSerializer? What problem does it attempt to solve?
A: Nillable value types. condiitonal serialization of fields using the Property specified pattern.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfSystemXmlSerializationXmlSerializerClassTopic.asp
  • Why are out parameters a bad idea in .NET? Are they?
A: Out parameters can be abused however. As a matter of good programming style if you find yourself writing a method with many out parameters then you should think about refactoring your code. One possible solution is to package all the return values into a single struct.

http://msdn.microsoft.com/vcsharp/programming/language/ask/refandout/default.aspx

.Net doesn’t verify that an out parameter is set inside a method that uses an out parameter before an exception is called. This mean that you may use an uninitialized parameter without the compiler catching on to this. Use ref parameters instead.

  • Can attributes be placed on specific parameters to a method? Why is this useful?
A: Yes. Best example is MarshalAs attribute used for PInvoke.

What Great .NET Developers Ought To Know - Part III

Ref:  Scott Hanselman


Senior Developers/Architects (Part I)
  • What’s wrong with a line like this? DateTime.Parse(myString)?
A: Parse converts date at any cost. What if user passes date in format MM/dd/yyyy whereas you are expecting in dd/MM/yyyy.Assume the user is passing 12/09/2006 meaning Dec 12, 2006, whereas Parse (based on the current locale) picked it up as Sep 12, 2006. The result is not something which you would like. Also Parse takes more time compared to other as it has to check for a gazillion formats. Instead if you know the format its better to go with ParseExact. Then why the hell do we have Parse? May be for the old VB customers it was an easier transition.
  • What are PDBs? Where must they be located for debugging to work?
A: A Program DataBase file (extension .pdb) is a binary file that contains type and symbolic debugging information gathered over the course of compiling and linking the project. A PDB file is created when you compile a C/C++ program with /ZI or /Zi or a Visual Basic, Visual C#, or JScript program with the /debug option. The Visual Studio debugger uses the path to the PDB in the EXE or DLL file to find the project.pdb file. If the debugger cannot find the PDB file at that location, or if the path is invalid, for example, if the project was moved to another computer, the debugger searches the path containing the EXE followed by the symbol paths specified in the Options dialog box (Solution Properties–>Debug Symbol Files node in VS.NET 2003). The debugger will not load a PDB that does not match the binary being debugged.
  • What is cyclomatic complexity and why is it important? 
A: Cyclomatic complexity is a software metric (measurement) in computational complexity theory. It is used to measure the complexity of a program. It directly measures the number of linearly independent paths through a program’s source code. Cyclomatic complexity is computed using a graph that describes the control flow of the program. The nodes of the graph correspond to the commands of a program. A directed edge connects two nodes if the second command might be executed immediately after the first command. This is done by counting the number of closed loops in the flow graph, and incrementing that number by one.For more info: http://sendhil.spaces.live.com/blog/cns!30862CF919BD131A!581.entry
  • Write a standard lock() plus “double check” to create a critical section around a variable access.
A: This calls for a separate entry in itself. http://sendhil.spaces.live.com/blog/cns!30862CF919BD131A!582.entry
  • What is FullTrust? Do GAC’ed assemblies have FullTrust?
A: Full Trust Permission Set Grants unrestricted permissions to system resources. My_Computer_Zone code group by default has has FullTrust permission. This can be changed using CASPOL.exe though.
  • What benefit does your code receive if you decorate it with attributes demanding specific Security permissions?
A: Allows administrators to see exactly which permissions your application needs to run, using PermViewPrevents your code from being exploited beyond what permissions it absolutely needs

Allows your application to forcibly fail instead of having to manually handle situations where it might be denied permissions it requires.
  • What does this do? gacutil /l | find /i "Corillian"
A: gacutil /l lists the assemblies in GAC. Find /i lists all the assemblies which have Corillian in their identity. (/i ignores case I suppose).
  • What does this do? sn -t foo.dll
A: Extracts the publick key token from the strongly named assembly foo.dll
  • What ports must be open for DCOM over a firewall? What is the purpose of Port 135?
A: 135 is used by Windows RPC. HKEY_LOCAL_MACHINESoftwareMicrosoftRpcInternet (Key) Ports (Multi Line String Value) specifies what other ports will be open.
  • Contrast OOP and SOA. What are tenets of each?
A: OOP Tenets – Abstraction, Encapsulation, Inhertiance, Polymorphism. SOA Tenats – (PEACE) – Policy based negotiation, Explicitness of boundaries, Autonomy, Contract Exchange Differences: Read this nice analogy. This is as best as it can get http://blogs.msdn.com/smguest/archive/2004/01/29/64871.aspx
  • How does the XmlSerializer work? What ACL permissions does a process using it require?
A: The XmlSerializer creates a temporary assembly with two types named XmlSerializationReader1, XmlSerializationWriter1 which derive from XmlSerializationReader and XmlSerializationWriter classes. These types are responsible for DeSerializing and Serializing respectively. The XMlSerializer constructors caches the assemblies emitted if you use one of these constructors
“System.Xml.Serialization.XmlSerializer(Type) System.Xml.Serialization.XmlSerializer(Type,String) “

Its recommended to use these. So the account under which host process is running must have Write, Delete permissions on the temporary directory. This the user profile temp directory for windows applications and the app specific folder under Temporary ASP.NET Files (in the framework directory) for ASP.NET applications
  • Why is catch(Exception) almost always a bad idea?
A: When you catch an exception, you’re stating that you expected this exception, you understand why it occurred, and you know how to deal with it. In other words, you’re defining a policy for the application. However, you shouldn’t catch Exception because a StackOverflowException or OutOfMemoryException exception could be thrown at any time. Hiding these fatal problems and allowing the application to continue running will cause unpredictable results.
  • What is the difference between Debug.Write and Trace.Write? When should each be used?
A: Debug.Write is compiled into a release build. Trace.Write gets compiled irrespective of the build configuration chosen. Trace is useful for production debugging (can be turned on off based on config at various levels / severity). Debug is useful for development environment debugging.
  • What is the difference between a Debug and Release build? Is there a significant speed difference? Why or why not?
A: A debug build generates a file containing debug symbols (.pdb); a release build does not.
A debug build generates extra instructions to accomodate the debugger (e.g. NOP instructions to assist your setting breakpoints); a release build does not include these.

A release build uses full optimizations when compiling which might include rearranging your code or inlining it for efficiency, a debug build doesn’t do this.

A debug build allocates extra memory on the heap for objects to facilitate detecting memory overwrite errors; a release build doesn’t do this.

A release build will thus be smaller, faster, and more efficient than a debug build.
More Info
http://p2p.wrox.com/topic.asp?TOPIC_ID=16066 

http://www.hanselman.com/blog/PermaLink.aspx?guid=a40c0d4f-66d0-4704-94f6-0efda4a44465

What Great .NET Developers Ought To Know - Part II

Ref:  Scott Hanselman


Mid-Level .NET Developer
  • Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.
    • Interface-oriented programming means defining and working strictly through interfaces.
      Object-oriented programming means defining defining a program using relationships between objects a classes (inheritance, polymorphism etc.)
      I’ve heard the buzz about AOP (aspect-oriented programming) but I have yet to study what exactly does it mean…
  • Describe what an Interface is and how it’s different from a Class.
    • An interface defines a contract without implementation. A class implements an interface.
  • What is Reflection?
    • Reflection is used to query .NET assemblies and types for information. It can also be used to create type instances, invoke methods and even emit .NET code at runtime (Reflection.Emit).
  • What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?
    • I’ve never used .NET remoting but I assume the difference is that remoting is not as interoperable as web services.
  • Are the type system represented by XmlSchema and the CLS isomorphic?
    • No.
  • Conceptually, what is the difference between early-binding and late-binding?
    • When using early-binding the call information is known at compile time.
      When using late-binding the call information is only known at runtime.
  • Is using Assembly.Load a static reference or dynamic reference?
    • Dynamic reference.
  • When would using Assembly.LoadFrom or Assembly.LoadFile be appropriate?
    • For loading assemblies from given file or folder (such as plugins etc).
  • What is an Asssembly Qualified Name? Is it a filename? How is it different?
    • The Assembly Qualified Name contains the assembly name, version and public key token and thus allows
      versioning and singing as opposed to a simple filename.
  • Is this valid? Assembly.Load(“foo.dll”);
    • No because “foo.dll” is not an assembly qualified name.
  • How is a strongly-named assembly different from one that isn’t strongly-named?
    • Strongly-named assemblies are signed using a privatepublic key pair which helps with code verification.
      signed assemblies could be placed in thee GAC.
  • Can DateTimes be null?
    • No because it is a structure and not a class.
  • What is the JIT? What is NGEN? What are limitations and benefits of each?
    • JIT means Just In Time compilation which means the code is being compiled just before it is supposed to run.
      This means longer startup time (because the code takes some time to compile) but more efficient compilation (since the compiler has more information about the target system etc.).
      NGen is used to pre-JIT code which yields faster startup time but the compiler produces less efficient code because it has less information.
  • How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?
    • It divides the objects into three generations.
      The first generation is used for short lived objects and is collected often (its cheap to collect it).
      The other two generations are used for longer term object.
      Non-deterministic finalization means that it is not known when the object’s finalizer is called since it is called when the GC decides to collect the object and not when the object falls out of scope etc.
  • What is the difference between Finalize() and Dispose()?
    • Finalize() is called by the runtime (the GC) and Dispose() is called by the user.
  • How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?
    • The using statement defines a scope at the end of which a given object will be disposed.
      Using the ‘using statement’ helps not to forget disposing of a disposable object.
      IDisposable is an interface used to define a way to dispose of objects in a deterministic manner.
      When the ‘using statement’ scope ends the Dispose() method is automatically called on the given object.
  • What does this useful command line do? tasklist /m “mscor*”
    • It shows all the processes that loaded a DLL with a name matching the given pattern. In this case we will see all the processes using the .NET framework.
  • What is the difference between in-proc and out-of-proc?
    • out-of-proc requires marshaling between two processes and thus slower.
  • What technology enables out-of-proc communication in .NET?
    • Remoting.
  • When you’re running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?
    • The ASP.NET worker process.

What Great .NET Developers Ought To Know - Part I


Ref:  Scott Hanselman

Everyone who writes code
  • Describe the difference between a Thread and a Process?
    • A process is a collection of threads (at least one) sharing the same resources (virtual memory, security context etc.).
      A thread is an entity in a process that can actually be executed on the CPU.
  • What is a Windows Service and how does its lifecycle differ from a “standard” EXE?
    • A Windows Service is a program that conforms to the rules of the SCM (Service Control Manager). The main difference is that it does not need a logged on user to activate it.
  • What is the maximum amount of memory any single process on Windows can address? Is this different than the maximum virtual memory for the system? How would this affect a system design?
    • Ok, I admit I had to check the MSDN documents for this.
      The maximum virtual memory for a 32-bit system is 4GB of which 2GB are availble to the user processes (3GB running a special configuration).
      This affects system design when when designing for memory intensive applications such as databases, enterprise applications etc…
  • What is the difference between an EXE and a DLL?
    • An EXE is an EXEcutable that contains an entry point and instructions to execute. A DLL only contains pieces of functionality to be used by an EXE (or another DLL).
  • What is strong-typing versus weak-typing? Which is preferred? Why?
    • strong-typing means a strict enforcement of type rules with no exceptions as opposed to weak-typing which allows well defined exceptions (such as assigning an int to a float in C++).
      While strong-typing can prevent many type errors, weak-typing is much more developer “friendly”.
      I assumed the preffered enforcement mechanism depends on the application at hand…
  • Corillian’s product is a “Component Container.” Name at least 3 component containers that ship now with the Windows Server Family.
    • I really have no idea what a “Component Container” is.
  • What is a PID? How is it useful when troubleshooting a system?
    • Process Identifier. I have never used it myself but I assume it can be used to kill the process or for loggingdebugging purposes.
  • How many processes can listen on a single TCP/IP port?
    • I am not 100% sure but I think the answer is One.
      The result of two or more processes listening to the same port would be erroneous since they’ll be “stealing” each other’s revieved information.
  • What is the GAC? What problem does it solve?
    • Global Assembly Cache. It resolves DLL hell, versioning etc…

10/06/2011

How to create a store procedure runs automatically every time an instance of SQL Server is started

USE master
go
CREATE PROCEDURE createMyGlobalTables  AS
   CREATE TABLE ##globalTemporary1
      (-- Blah blah (insert DDL here)
   CREATE TABLE ##globalTemporary2
      (-- Blah blah (insert DDL here)
--and so on….
   CREATE TABLE ##globalTemporaryn
      (-- Blah blah (insert DDL here)

go
EXEC sp_procoption 'createMyGlobalTables', 'startup', 'true'