Friday, September 07, 2007

Cannot resolve collation conflict for equal to operation

In SQL Server 2000,when you have character data stored with different collation sequences, you need to be aware that comparing columns becomes more involved

Columns with the same collating sequences can be compared or joined without any additional considerations

This mainly occurs when the temporary tables have a different collation sequence than the tables in the database.

The solution is to have the tables in the database to be created without any collation sequence. This will enable the tables to take the default collation of the database

Tuesday, March 13, 2007

Mid level developer - Qs from Scott Hanselmans Computer Zen

I hope to write all the answers. Watch this space!

Describe the difference between Interface-oriented, Object-oriented and Aspect-oriented programming.

Interface Oriented programming

= Programming to an Interface.

Object oriented programming = Using the object oriented concepts such as Encapsulation,Inheritance,Polymorphism

Aspect oriented programming = <>


Describe what an Interface is and how it’s different from a Class.

Interface has no implementation.

Classes have implementation and they may implement the Interface.

Interface is a good way to design a software since it defines a contract for the classes.

What is Reflection?

Reflection provides objects that encapsulate assemblies, modules, and types.

You can use reflection to dynamically create an instance of a type, bind the type to an existing object, or get the type from an existing object.

You can then invoke the type's methods or access its fields and properties.

Example

Imagine,you are in visual studio IDE (Integrated devolopment environment) and as you type "object." you would see all the methods,properties and events associated with that object.

An other example would be an Object browser.The code attached here,loads all assemblies and displays each class,its contructors, methods, properties and events in tree view.

What is the difference between XML Web Services using ASMX and .NET Remoting using SOAP?


Are the type system represented by XmlSchema and the CLS isomorphic?


Conceptually, what is the difference between early-binding and late-binding?


Is using Assembly.Load a static reference or dynamic reference?


When would using Assembly.LoadFrom or Assembly.LoadFile be appropriate?

LoadFile method is supported only in version 1.1 of the .NET Framework

Use the LoadFile method to load and examine assemblies that have the same identity, but are located in different paths.

Do not use LoadFile to load assemblies that you want to execute. LoadFile does not load files into the LoadFrom context, and does not resolve dependencies using the load path, as the LoadFrom method does.

LoadFile is useful in this limited scenario because LoadFrom cannot be used to load assemblies that have the same identities but different paths; it will load only the first such assembly.


What is an Asssembly Qualified Name? Is it a filename? How is it different?

An assembly's name is stored in metadata and has a significant impact on the assembly's scope and use by an application.

A strong-named assembly has a fully qualified name that includes the assembly's name, culture, public key, and version number.

The runtime uses this information to locate the assembly and differentiate it from other assemblies with the same name.

For example, a strong-named assembly called myTypes could have the following fully qualified name:

"myTypes, Version=1.0.1234.0, Culture="en-US", publicKeyToken=b77a5c561934e089c


In this example, the fully qualified name indicates that the myTypes assembly has a strong name with a public key token, has the culture value for US English, and has a version number of 1.0.1234.0.


Is this valid? Assembly.Load("foo.dll");

No this should be loaded with a fully qualified assembly name


How is a strongly-named assembly different from one that isn’t strongly-named?

A strong name consists of the assembly's identity—its simple text name, version number, and culture information (if provided)—plus a public key and a digital signature

Strong names guarantee name uniqueness by relying on unique key pairs. No one can generate the same assembly name that you can, because an assembly generated with one private key has a different name than an assembly generated with another private key

It helps in avoiding DLL hell.

Can DateTimes be null?


What is the JIT? What is NGEN? What are limitations and benefits of each?

JIT comes into play during EXECUTION of the code.

Before you can run Microsoft intermediate language (MSIL), it must be converted by a .NET Framework just-in-time (JIT) compiler to native code, which is CPU-specific code that runs on the same computer architecture as the JIT compiler.

JIT compilation takes into account the fact that some code might never get called during execution. Rather than using time and memory to convert all the MSIL in a portable executable (PE) file to native code, it converts the MSIL as needed during execution and stores the resulting native code so that it is accessible for subsequent calls

NGEN

The Native Image Generator (Ngen.exe) is a tool that improves the performance of managed applications.

Ngen.exe creates native images, which are files containing compiled processor-specific machine code, and installs them into the native image cache on the local computer.

The runtime can use native images from the cache instead using the just-in-time (JIT) compiler to compile the original assembly.

http://msdn2.microsoft.com/en-us/library/6t9t5wcf(VS.80).aspx is a good link on comaprison between NGEN and JIT


How does the generational garbage collector in the .NET CLR manage object lifetime? What is non-deterministic finalization?


What is the difference between Finalize() and Dispose()?

Finalize

Allows an Object to attempt to free resources and perform other cleanup operations before the Object is reclaimed by garbage collection.

Finalize operations have the following limitations:
The exact time when the finalizer executes during garbage collection is undefined. Resources are not guaranteed to be released at any specific time, unless calling a Close method or a Dispose method.

The finalizers of two objects are not guaranteed to run in any specific order, even if one object refers to the other. That is, if Object A has a reference to Object B and both have finalizers, Object B might have already finalized when the finalizer of Object A starts.

The thread on which the finalizer is run is unspecified.

Dispose


How is the using() pattern useful? What is IDisposable? How does it support deterministic finalization?


What does this useful command line do? tasklist /m "mscor*"


What is the difference between in-proc and out-of-proc?


What technology enables out-of-proc communication in .NET?


When you’re running a component within ASP.NET, what process is it running within on Windows XP? Windows 2000? Windows 2003?

Tuesday, February 06, 2007

Debugging Cassini and Debugging GAC dlls

My Question in ASP.NET forums

"
Hello,
I am trying to debug the source code of Cassini.

I have modified 2 lines of the build.bat file in this way

csc /t:library /keyfile:Cassini.snk /r:System.dll /r:System.Web.dll /debug /out:Cassini.dll AssemblyInfo.cs ByteParser.cs ByteString.cs Connection.cs Host.cs Messages.cs Request.cs Server.cs

csc /nologo /define:DEBUG /t:winexe /r:System.dll /r:System.Drawing.dll /r:System.Windows.Forms.dll /r:Cassini.dll /win32icon:CassiniWebServer.ico /res:CassiniWebServer.ico,CassiniWebServerIcon /out:CassiniWebServer.exe CassiniWebServerMain.cs

Since the Cassini is installed in the GAC. I am unable to debug.

Therefore I removed the assembly from the GAC and modified the build.bat file accordingly.
When I try to debug the solution, I get an exception in

_host = (Host)_appManager.CreateObject(appId, typeof(Host), _virtualPath, _physicalPath, false /*failIfExists*/);

indicating that the file and assembly could not be found.
The error is gone after I remove from the GAC but I am not able to debug it.

Found the solution also.
The solution is

Thanks to Robert Bogue [MVP] blog
Have a look at the link to debug GAC dlls
http://thorprojects.com/blog/archive/2005/08/30/204.aspx
Getting the content again from the blog
"
There are sometimes when your assembly almost has to be in the GAC and when you need to debug it. This was difficult since if you registered a .NET assembly into the GAC the debugger wouldn't break on it. This is because the .PDB file information didn't get loaded since it's not in the same directory as the DLL. Here's how to work around that.

1) Install the Assembly in the GAC
2) Start-Run, %SYSTEMROOT%\Assembly\GAC
3) Navigate into the folder with name of the DLL that you want to debug
4) Navigate into the folder with the version number and public key that you want
5) Copy the .PDB file into this directory

Now you'll be able to run a debugger against code running in the GAC.
"
For me in Step3 the path was
C:\WINNT\assembly\GAC_MSIL\Cassini\2.0.60306.0__a2c3042d130f02aa

Thursday, January 18, 2007

Everyone who writes code - Answers

Question:Describe the difference between a Thread and a Process?

Answer:
A program in execution is known as a process.
A process may have a single thread.
A process may have multiple threads. Threads are spawned from a process.
===========================================================
Question:What is a Windows Service and how does its lifecycle differ from a "standard" EXE?

Answer:
The "standard EXE" exits from memory when it is closed.
The Windows Service only exits from memory when the service is stopped.

==============================================================

Question: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?

Answer:
========================================================
Question:What is the difference between an EXE and a DLL?

Answer:
A DLL is a dynamic link library. When a process loads a DLL, the DLL is loaded into the memory once. When another process makes a call to the same DLL, the DLL is not loaded into memory again.

A EXE is always loaded into memory. Each instance of the EXE is a process. It has its own address space.
============================================================
Question:What is strong-typing versus weak-typing? Which is preferred? Why?

Answer:
When the type of an object is known, then this strongly typed.
example,
Dim i as Integer

When the type of an object is known, then this is weakly typed.
example,
Dim obj as Object

For performance reasons, strong typing is preferred.

But in certain cases, late binding is required, therefore weak typing is necessary
=========================================================

Question:Name at least 3 component containers that ship now with the Windows Server Family.

Answer:
===============================================
Question:What is a PID? How is it useful when troubleshooting a system?
Answer:
PID is Process identification number. This would help to identify the process which causes the problem
=======================================================
Question:How many processes can listen on a single TCP/IP port?
Answer:
===================================================
Question:What is the GAC? What problem does it solve?
Answer:GAC is the Global Assembly Cache. If a number of applications use the same DLL, the DLLs can be installed in the GAC and the applications can use the same DLL. This helps in deplyment issues related with enterprise applications using the same DLL

Singleton design pattern

I have a interest in design patterns. Would be posting several useful links on design patterns . Starting off with the simplest design pattern.

http://msdn2.microsoft.com/en-us/library/ms998426.aspx is a MSDN link on the Singleton Design pattern. This is a very simple design pattern.

This article has an implementation with C#.It uses the lock keyword for mutual exclusion.

What is lock?

The lock keyword marks a statement block as a critical section by obtaining the mutual-exclusion lock for a given object, executing a statement, and then releasing the lock. This statement takes the following form:

Object thisLock = new Object();
lock (thisLock)
{
// Critical code section
}

==============================================================

http://en.wikipedia.org/wiki/Singleton_pattern is the wikipedia link on the Singleton design pattern.

Monday, January 15, 2007

SQL Server Database Publishing wizard

Microsoft has launched a RC1 Database Publishing wizard. This is pretty neat utility.
We can script the database objects ( tables , SPS,UDFs and others ) and also the DATA of the database. The DATA part of the scripting was particularly new.
http://www.codeplex.com/sqlhost/Wiki/View.aspx?title=Database%20Publishing%20Wizard
has the free download.

Tuesday, January 02, 2007

ASPNet account and SQL Server

If you use Integrated Security = True in the DB connection string for a website, make sure that the machine's ASPNET account( machine name\aspnet account ) has access to the database.

Very simple information but effective at times.

Tuesday, December 19, 2006

FTP using IE

You can use IE to do neat FTPs
use ftp://username@IP address
This should work fine. No command line arguments

Thursday, December 07, 2006

Remote connections to SQL Server 2005 Express

Try connecting a SQL server 2005 Express server from a remote machine, you would get an error.

Error would be something like this
============================
Message : An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: SQL Network Interfaces, error: 28 - Server doesn't support requested protocol)

This is because the default setting for SQL server 2005 Express allows local connections only.

For configuring the remote connections ,

  1. go to the SQL Server Surface area configuration application and click on Remote connections,select Local and Remote connections
  2. Restart the SQL Server service


SQL Server 2005 - Adding an user

Should be a very basic stuff for most.
But it took me sometime.Therefore blogging it so that I do not waste a minute in it later on
  1. Add the user to the server level by ensuring that in the User Mapping section ( Right click Properties ) , the default schema for the databases is dbo.
  2. The role membership in the User Mapping section ( Right click Properties ) should be db_owner
  3. Go to the respective database such as Pubs where the user has been added say user1
  4. Right click the properties of user1
  5. Ensure that the section( Schemas owned by the user ) has the db_owner checked
  6. Ensure that the section( Database role membership) has the db_owner checked

Thursday, November 23, 2006

VB Express error - Strange solution

Today I was working with VB express and did the following
  • Created a new permission set
  • Created a new code group
  • Associated the code group with the permission set.
  • Created a strong name for the simple windows app that I was working with.
  • Associated the assembly with the code group

Then after doing such simple things got the following error while trying to debug








And then what next ?
Googled .
Found in the MSDN forums that there were many souls like me who had racked their brains on this.
Solution:
===========
Turn on the Terminal Services from the Control Panel->Settings->Services.
And the VB Express works like a charm as before .
Strange isnt it ? I will research more if you find why this is so. Any of you reading this can post comments on this.

Tuesday, November 21, 2006

Local SQL Server 2005 DB and Enterprise DAB

Experiment1
============
Add a SQL database from the Solution explorer using Add New item.
Once you add it , the connection string would be present in the app.config
add name="My.MySettings.Database2ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=DataDirectory\Database2.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient"


Use the Enterprise Library DAB and change the default database to point to My.MySettings.Database2ConnectionString
dataConfiguration defaultDatabase="My.MySettings.Database2ConnectionString"

Experiment2
===========

You can also have a .MDF and a .LDF file in the file system as in
C:\Ambarish\Database2.mdf

Change the connection string in the app.config to
add name="My.MySettings.Database2ConnectionString" connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=C:\Ambarish\Database2.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient"

=========================================================



Use the MVC pattern ( here only the controller code is present ) to connect to the DB

============================================
Public Sub GetTable1Data(ByRef ds As DataSet)
Dim db As Database
Dim strCommand As String
Dim dbCommand As DbCommand
Try
db = DatabaseFactory.CreateDatabase()
strCommand = "dbo.uspGetDataTable1"
dbCommand = db.GetStoredProcCommand(strCommand)
ds = db.ExecuteDataSet(dbCommand)
Catch ex As Exception
Throw ex
Finally
db = Nothing
End Try
End Sub


==============================

Monday, October 23, 2006

Wednesday, October 11, 2006

SQL Server Express XCOPY

The XCOPY feature of SQL Server Express is a good feature which would help applications to deploy databases very easily.
This is similar to deploying Microsoft Access databases

Sample code from the 101 VB samples (VB101SamplesWinForms\UsingDataGridView)
on how to connect to MDF files have been added
======================================================
Dim connectStringBuilder As New SqlConnectionStringBuilder()
connectStringBuilder.DataSource = ".\SQLEXPRESS"
connectStringBuilder.AttachDBFilename = "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Data\AdventureWorks_Data.mdf"
connectStringBuilder.IntegratedSecurity = True
connectStringBuilder.UserInstance = True

==========================================
Some very good links are as follows:

Tuesday, October 10, 2006

Asynchronous Tasks in .NET 2.0

In .NET 2.0, a new class BackgroundWorker Class has been introduced.
This would help in Asynchronous Tasks.
These are paricularly helpful when there is a long running task such as downloading a file,uploading a file,printing a large number of documents.

Good links are as follows:
====================

TreeView articles

Some of the good treeview links
=============================
  1. http://www.codeproject.com/vb/net/TreeViewDragAndDrop.asp is a good link for implementing Drag and Drop. Follow the links in the page to have other good treeview links.

Monday, October 09, 2006

Web Services Performance

1. http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wse3.0/html/4344d43e-ceb4-43a9-8f8c-6a3f89f786bd.asp. This is “How to: Enable a Web Service to Send and Receive Large Amounts of Data”
2. How to: Stream Large Amounts of Data from a Web Service . The URL is http://msdn.microsoft.com/library/default.asp?url=/library/en-us/wse3.0/html/4344d43e-ceb4-43a9-8f8c-6a3f89f786bd.asp
3. http://www.codeproject.com/soap/MTOMWebServices.asp

are good links relating to Web Services and uploading and downloading data
Adda is the Bengali for discussion.Bengali is a language like English.