Have you ever created a Database project and after some time you are not able to load it in the Visual Studio? Probably you might be getting following error:
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: 26 - Error Locating Server/Instance Specified)
The database project requires an active database connection to load at design time. Probably it uses that to compile/verify scripts. The problem here is Visual Studio is not able to connect to any such instance. Following are few solutions (these worked for me)
- Make sure the instance to which you want to connect is running and allows remote connections.
- After performing step 1, if it is still not loading then you may need to start the SQL Browser Service. Make sure it’s running.
- If the problem is still there, it has to be fixed from Visual Studio itself. Actually database project do not store to which instance it can connect. It’s a Visual Studio setting. In VS2008 go to Tool > Options > Database Tools > Design-time Validation Database > Connection Options. Specify your instance name here like “.\SQLEXPRESS”
If the problem is still there post it to MSDN forums
Ankit
While importing (drag/drop) your webpart to any SharePoint page, if you receive an error stating ‘Cannot import webpart’ or ‘unable to add selected web part(s)’… here is the check list you should look for:
- Make sure the webpart class is inherited either from Microsoft.SharePoint.WebPartPages.WebPart or System.Web.UI.WebControls.WebParts.WebPart
- The webpart class needs to be declared public.
- Safe controls entry in web.config file.
- If you are referring a webpart from GAC (i.e. assembly containing webpart class is placed in GAC) make sure the GAC version is the latest build and IIS is re-started.
- Ankit
I was playing through SharePoint object model and somewhere (don’t remember right now!) got an exception stating “ServerContext not set to an instance”.
My solution for this: Installed SSP (Shared Services Provider) and this problem is solved!
[ Edited:2008-03-24
I got this error while playing with stsadm.exe command
]
Few frequently asked question for ASP.NET developers:
- The Identity Selector dialog box is displayed only for SSL protected pages. Therefore you are required to deploy your application on a Web server and install a SSL Certificate.
- Windows CardSpace does not work with Self Signed Certificates and will die horribly. These certificates do not have CRL field. It contains a URL that CardSpace will check for the revocation list.
- For ASP.NET developers there is Toolbox control written by Christian Arnold. Add this to your Toolbox and you won’t need to write a single line of code. Watch demo.
- When you use CardSpaceLogin controls you must run application over SSL. The application pool also need to be run under Local System’s identify; otherwise w3wp.exe process will not be able to retrieve server’s private key. In such case you may end up with error stating “Keyset does not exist”. Note: This is not advisory if the application pool is shared with other Web applications. [ Edited: Refer Barry Dorrans comment for more details.]
- When using Information cards there is nothing like passwords.
- CardSpaceLogin controls are integrated with your identify providers such as Forms Authentication. For example: If you use Information Card to register a user, his details are reflected in the identify source.
It’s a best practice to add comment when you do check-in to the source control. A text comment is associated with the change you made to the item. Some of the times you need to find a particular comment, but the View History tool available with Visual Studio/TFS is limited that you can’t make a search in the history results. Say you want to find all check-ins by a particular user

Here comes the purpose of this small add-in. It provides search within history comments and find a particular change-set instead of traversing the whole list. The plug-in goes one step forward and facilitates free text search in change-set fields. For example you can use change-set id, username or even date-time as search keywords!!!
The major steps involved in developing this add-in are:
- Writing an add-in for Visual Studio 2005,
- Getting file history from Team Foundation Server (TFS),
- Look for the selected item in the Visual Studio IDE,
- Free text search along with the tools to compare two files.
(more…)
Hmmm… a new tool in my hands
… and following equation makes me crazy about it…
C# 2.0 + ADO.NET = LINQ = C# 3.0
In simple words Language Integrated Query (LINQ) exposes the power of SQL queries within C# syntax. This technology along with its tools allows you to connect to SQL database, extract metadata, build typed datasets/classes (using C# Generics) and make you use them along with C# syntax using just two lines of code. And not necessarily SQL databases, it can execute on any collection type.
int[] numbers = { 5, 4, 1, 3, 9, 8, 6, 7, 2, 0 };
var lowNums =
from n in numbers
where n < 5
select n; Console.WriteLine("Numbers < 5:");
foreach (var x in
lowNums)
{
Console.WriteLine(x);
}
Have a look at Linq Project @ MSDN and 101 Samples all to sense this. Here in this short -n-simple post I’m just showing how to do things for databases stored as *.mdf files and generate wrapper classes.The LINQ preview includes SqlMetal.exe, a utility to auto-generate a strongly-typed C# DataContext class file from an SQL Server 2000 or 2005 database’s metadata with this execution syntax:
$>sqlmetal.exe /namespace:NWind /language:csharp /code:Northwind.cs “c:\ Northwind.mdf”
- Ankit
My presentation on WebServices Basics is available for download to the *valuable visitors* of my blog. Here is the content:
- Web services - Definition: A web service is a collection of protocols and standards used for exchanging data between applications or systems.
- Characteristics
- Demo: Writing a simple WebService in Visual Studio 2005 & Consuming WebServices
- Technologies: XML (eXtensible Markup Language), SOAP (Simple Object Access Protocol), WSDL (Web services description language), UDDI (universal description, discovery, and integration)
- SOAP: SOAP is an open protocol specification defining a uniform way of performing RPCs using HTTP as the underlying communications protocol with XML for the data serialization.
- Drilling inside SoapHttpClientProtocol class
- Advantages of Web services
- SOA – Service Oriented Architecture, Four Tenets
Thanks,
~ Ankit
These days I’m writing a tool for Visual Studio that integrates with Team Foundation Server. This post is about how to retrieve/fetch history of a file from source control server using TFS-SDK. Following function takes server name and file path as input and returns an enumerator holding Changeset objects.
public static IEnumerable FetchHistory(string serverName, string filePath)
{
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer(serverName);
VersionControlServer vcs = tfs.GetService(typeof(VersionControlServer)) as VersionControlServer;
ExtendedItem[] itemArray1 = vcs.GetExtendedItems(filePath, DeletedState.NonDeleted, ItemType.Any);
if ((itemArray1 == null) || (itemArray1.Length == 0))
throw new Exception(“There are no items.”);
ExtendedItem item1 = itemArray1[0];
IEnumerable enumerable1 = vcs.QueryHistory(filePath,
VersionSpec.Latest, item1.DeletionId,
(item1.ItemType == ItemType.Folder) ? RecursionType.Full : RecursionType.None,
“”, new ChangesetVersionSpec(1),
VersionSpec.Latest, 0×7fffffff, true, false);
return enumerable1;
}
To compile this successfully you also need to add references of following two assemblies found at [VS installation directory]\Common7\IDE\PrivateAssemblies\:
Microsoft.TeamFoundation.Client.dll
Microsoft.TeamFoundation.VersionControl.Client.dll
Call to this function should be made as follows:
FetchHistory(“[serverName]”, “$/Project1/Class.cs” );
- Ankit
One nice feature of WPF (Windows Presentation Foundation, .Net 3.0) is the integration of 3D library with the existing framework. Today I worked with Viewport3D class. This class handles it all for managing 3D views. The “Hello World” example I coded here basically demonstrates three features:
- Loading XAML dynamically at runtime
- Playing with 3D objects using Viewport3D and make them rotate using mouse.
- Creating transparent and full-screen windows
Let’s drill down to the technical details of above three aspects:
Firstly, loading XAML runtime can be achieved using System.Windows.Markup.XamlReader class. The Load function takes a stream object (containing XAML source) and return appropriate UI control. Actually, it returns the root control in the stream.
FileStream fs = File.OpenRead(fileName);
this.view3D = (Viewport3D) System.Windows.Markup.XamlReader.Load(fs);
Secondly, the class Viewport3D does it all for you to handle 3D objects. Here we have just hooked mouse events that allows rotation of 3D object in all directions. Moreover you can zoom in/out using right mouse button. Thanks Daniel for writing TrackBall class.
Lastly, setting few parameters as below we can make a Window appear transparent and full-screened:
this.win = new Window();
win.Content = view3D;
win.ShowInTaskbar = false ;
win.Background = Brushes.Transparent ;
win.AllowsTransparency = true;
win.WindowStyle = WindowStyle.None ;
win.WindowStartupLocation = WindowStartupLocation.CenterScreen ;
win.WindowState = WindowState.Maximized;
win.Show();
Well, I guess that’s enough for the first WPF post.
Download the source code for sample application: Load-3D-XAML-Runtime.zip
Thanks for reading.
~ Ankit
I love writing extensions for applications and filling gaps in between making the world simpler (interacting with each other, giving users flexibility in switching from one application to another.) The power of any application (especially Internet Browsers) lies in how features enriched it is. One of the way to achieve this is to lay down extensible architecture and promote developers to write extensions for you application. Moreover such architecture should provide
- the simplest method to write an extension in few seconds (“hello world” example)
- more flexible in term of autonomy to developer for by exposing a rich set of API, that they can code almost everything,
- and the last, limiting them touching sensible data of user.
Well, the power of FireFox lies in more than thousands of extensions that it provides. This could also have been for Internet Explorer, if Microsoft has provided detailed documentation and samples for Internet Explorer when they released IE 5. Over the years Microsoft had always concentrated on the Web development front of IE, not on the extensibility part of it even though providing great ways to extend.
Let’s go through Internet Explorer for writing the simplest extension in just 5 minutes. So, what we want to do? Here I;m showing how to access Html DOM and change it on the fly. All you need to know is simple JavaScript and basic programming concepts. Here are the steps on MSDN that details adding a context menu to Internet Explorer.
(more…)
If you are looking for maps and routs in india, land to Live.com
Route from Ahmedabad to Pune
Open registry editor and add a new key under
HKEY_CURRENT_USER\Software\Microsoft\Internet Explorer\SearchScopes\
This is the place from where IE7 (Microsoft Internet Explorer 7) builds search engine details. Now the things are obvious, add two string values named “DisplayName” & “URL”. For example if you want to add a Google Blog search, use URL as http://www.blogsearch.google.com/blogsearch?q={searchTerms}
Here {searchTerm} is the string appeared in the search text box.
(more…)
Here I’m explaining how to create a webpage that offers download on button click event, instead of showing a direct link to the download file. The following C# piece of code when inserted in button click event on ASP.net web page, gives you an effect of dynamic download, hiding download URL.
HTTP requests and responses travel along with lot of headers, just like meta-data for the request/response. Here is the list of some of them, Response Headers. Following example makes use of them. The method implemented here is just for the sake of example, and not to be used on Web Servers. Problem here is we are reading one byte, writing to response and flushing the response again-n-again. Here for every single byte, a packet is created and sent to the client, creating packet flood! Using a buffer of at least 1000 bytes before flushing is recommended.
Response.Clear();
String fileNameToSend = “downloadTest.txt”;
//Make sure following file exists and it’s size is less than 2KB.
FileInfo file = new FileInfo( “C:test.txt” );
String value = “attachment; filename=”" + fileNameToSend + “”";
Response.ContentType = “application/octet-stream” ;
Response.AddHeader(“Content-length: “, file.Length.ToString());
Response.AddHeader(“Content-Disposition”, value );
FileStream fs = null ;
try {
fs = File.OpenRead(“C:test.txt”);
BinaryReader br = new BinaryReader(fs);
while (true)
{
// EOF exception to exit loop, not a good way!
Response.Write((char)br.ReadByte());
System.Threading.Thread.Sleep(5);
Response.Flush();
}
}
catch {}
finally
{
if (fs != null )
fs.Close();
}
Response.End();
What more you can do with this?
- allow users to download only one file at a time,
- limit bandwidth for specific users, etc.
~ ankit
Besides providing free domains with Office Live, they have entered into active competition against Google. Google started giving free domain-email hosting, Google/Hosted for small companies on there servers with GMail, here comes Microsoft with … Windows Live™ Custom Domains.
More @ ideas.live.com. Lots of stuff under the brand name “Live”.
- Live Shopping — Find the products you’re looking for, read review, recommend.
- Live Mail Desktop Beta — One place to see e-mail from multiple accounts. I guess this is possible with Outlook 2007.
- Live Expo Beta — Expo is an online social marketplace where you can exchange goods/ideas or information with anyone you choose. Just like Google Base.
- Live Favorites — now that your Internet Explorer Favorites can travel with you.
Pumping new services over-n-over. Now the question is who will survive. One thing is clear that this competition has given lots of free stuff to users. The online world is being better, simpler and effortless. The old tradition in which you have to buy a service is changed. This is actually Web 2.0!
Frankly speaking, before buying anything search well for it!
~ ankit
“why not to write about Microsoft, when working on their technologies?” so I created a separate category for it and now, I’d be writing about them regularly. Here is the first one, about their security contest.
Microsoft India has come up with security competition Security Shoot Out. In the stage one, you have to answer 30 security questions, and they will shortlist 1000 participants whom have to answer 30 questions again for stage two. For the last stage, 100 participants, will be given code base on .NET 2.0 having security related bugs. Stage 1 has been started from 20th March & will end on 19th April 2006.
And about prizes, killing custom build Scorpio passion, laptops, pocket PCs and may be an offer to work on latest technologies with Microsoft.
|
CONTEST STAGE
|
PRIZE CATEGORY
|
PRIZES
|
|
Stage -I
|
1000 Early Bird
|
T-Shirt
|
|
Stage -I
|
Top 5000
|
Developer Security CD
|
|
Stage -II
|
Top 1000
|
Book on secure code writing
|
|
Stage -II
|
Top 500
|
Microsoft Security Certification Voucher
|
|
Stage -III
|
Top 100
|
USB 2.0 powered 80 GB external HDD
|
|
Stage - III
|
Top 10
|
Pocket PC with 1 GB Memory Card
|
|
Stage- III
|
Top 3
|
Laptop
|
|
Stage -III
|
(”Winner”)
|
1. Free TechEd India Attendance 2. Customized Scorpio Passion (car)
|
~ Ankit