ApexSQL Search is a free tool that can be used to search SQL Server databases for objects as well as creating charts that illustrates dependencies within the database. The tool can be found here.
The tool is an add-in for Visual Studio and Sql Server Management Studio. After installation, ApexSQL will show up in the menu for both applications. Mostly, I run it when in Visual Studio. Just open the Server Explorer window and create a database connection. Select the connection and choose one of the options from the APEXSQL menu. Select View Dependencies to open up a Dependency Viewer window that will show you a chart with every dependency in the database. This will be overwhelming, so you can toggle off different dependency types in the toolbar.
UPDATE 2/15/2019: The View Dependencies feature is no longer part of the free ApexSql tool. It looks like this is now part of their ApexSql Analyzer tool which is most definitely NOT free.
Friday, May 16, 2014
Thursday, May 15, 2014
Windows Communication Foundation
I like to think of Windows Communication Foundation (WCF) as the portion of the .NET Framework that concerns the hosting and consumption of services. A "service" can be thought of as a server program that exposes a set of operations that is accessible to client programs over a network. A service that provides its operations over the internet can be thought of as a "web service".
A WCF service consists of:
If you wanted to host this in IIS, just publish the files to a site. If you wanted to host it in a Windows Form app, do something like this:
Consuming a web service is pretty straightforward. Just add a Service Reference in Visual Studio and a proxy class will be generated for you to call the service operations with:
The client configuration is very similar to the server configuration. Essentially to connect to a service, the client must use the same configuration.
A WCF service consists of:
- An interface that defines both the service and its operations.
- A class that provides the implementation of the operations.
To create a WCF service in Visual Studio:
- Add an ASP.NET Web Application project (Use the "Empty" template) or a WCF Service Application project.
- Then add a WCF Service item.
The WCF service must be hosted. The obvious choice is to host it in IIS. However, the service can be hosted in any .NET Windows application as well.
How does the host know to listen for requests? Setting in the web.config file. The following configuration indicates to the .NET framework that a WCF service is running:
<system.serviceModel> <services> <service name="ProjectName.DayOfTheWeekService"> <endpoint address="http://localhost:8000/DayOfTheWeekService.svc" binding="basicHttpBinding" name="basicHttpBinding_IDayOfTheWeekService" contract="ProjectName.IDayOfTheWeekService" /> </service> </services> </system.serviceModel>
If you wanted to host this in IIS, just publish the files to a site. If you wanted to host it in a Windows Form app, do something like this:
Private MyServiceHost As System.ServiceModel.ServiceHost Private Sub ButtonStart_Click(sender As Object, e As EventArgs) Handles ButtonStart.Click MyServiceHost = New System.ServiceModel.ServiceHost(GetType(ProjectName.DayOfTheWeekService)) MyServiceHost.Open() End Sub
Dim DayOfWeekProxy As New DayOfTheWeekServiceReference.DayOfTheWeekServiceClient("BasicHttpBinding_IDayOfTheWeekService") Console.WriteLine(DayOfWeekProxy.GetDayOfTheWeek(InputDate))
The client configuration is very similar to the server configuration. Essentially to connect to a service, the client must use the same configuration.
<system.serviceModel> <bindings> <basicHttpBinding> <binding name="BasicHttpBinding_IDayOfTheWeekService" /> </basicHttpBinding> </bindings> <client> <endpoint address="http://SERVERCOMPUTER:8000/DayOfTheWeekService.svc" binding="basicHttpBinding" bindingConfiguration="BasicHttpBinding_IDayOfTheWeekService" contract="DayOfTheWeekServiceReference.IDayOfTheWeekService" name="BasicHttpBinding_IDayOfTheWeekService" /> </client> </system.serviceModel>
Tuesday, May 13, 2014
MVC Exception Handling
This is a followup post to my original post about simple .NET exception handling.
The ASP.NET MVC Framework contains an attribute named HandleErrorAttribute. You can decorate a controller or an action simply by typing <HandleError> above the controller or action definition. If an unhandled exception occurs anywhere in the scope decorated with HandleErrorAttribute, MVC will display a view named "Error" to the user automatically. Typically, this view is generated for you when you create a new MVC application and is placed in the Shared folder. The HandleErrorAttribute will only work if you have customErrors turned on in your web.config. HandleErrorAttribute works great but it doesn't log. In order to add this functionality to the attribute you need to create a new class that inherits from the HandleErrorAttribute like this:
Now, if you want to use your new attribute, you would just type <HandleErrorAndLog>. You can globally apply this attribute to everything in your application by editing the FilterConfig.vb file like this:
Apparently, there are certain exceptions that this attribute does not handle such as HTTP exceptions that occur outside of the MVC context. To ensure these errors are handled, you should also log errors in the MvcApplication_Error event of the Global.asax.vb file. Be sure to set the defaultRedirect attribute of the customErrors node in the web.config file to the Error View. You will need to create an action method that will display the Error view when it is redirected in this way..
The ASP.NET MVC Framework contains an attribute named HandleErrorAttribute. You can decorate a controller or an action simply by typing <HandleError> above the controller or action definition. If an unhandled exception occurs anywhere in the scope decorated with HandleErrorAttribute, MVC will display a view named "Error" to the user automatically. Typically, this view is generated for you when you create a new MVC application and is placed in the Shared folder. The HandleErrorAttribute will only work if you have customErrors turned on in your web.config. HandleErrorAttribute works great but it doesn't log. In order to add this functionality to the attribute you need to create a new class that inherits from the HandleErrorAttribute like this:
Public Class HandleErrorAndLogAttribute Inherits HandleErrorAttribute Public Overrides Sub OnException(filterContext As ExceptionContext) If Not filterContext.ExceptionHandled Then Dim MyException As Exception = filterContext.Exception ... 'Logging code goes here ... MyBase.OnException(filterContext) End If 'filterContext.Result = New ViewResult With {.ViewName = "Error"} End Sub End Class
Now, if you want to use your new attribute, you would just type <HandleErrorAndLog>. You can globally apply this attribute to everything in your application by editing the FilterConfig.vb file like this:
Public Module FilterConfig Public Sub RegisterGlobalFilters(ByVal filters As GlobalFilterCollection) 'filters.Add(New HandleErrorAttribute()) filters.Add(New HandleErrorAndLogAttribute()) End Sub End Module
Apparently, there are certain exceptions that this attribute does not handle such as HTTP exceptions that occur outside of the MVC context. To ensure these errors are handled, you should also log errors in the MvcApplication_Error event of the Global.asax.vb file. Be sure to set the defaultRedirect attribute of the customErrors node in the web.config file to the Error View. You will need to create an action method that will display the Error view when it is redirected in this way..
Thursday, May 8, 2014
Network Basics
TCP/IP
Most computer networks today including the Internet use TCP/IP. An IP address uniquely identifies each computer on a TCP/IP network. You may have noticed that your home computer has an IP address that is not exactly unique. This is because all computers that are connected to your home router make up your own "private" network. Since your network is private, no computers from outside your network will be communicating directly with your computer. Therefore all private networks use IP addresses in the 192.168.x.x range.
What you think of as your home router or modem is actually a combination of things.
It is a modem. A modem is responsible for converting the communications into a form that can be sent over telephone or cable wires.
It is a router. The router routes packets of data to the computers they are bound for.
It is a gateway. A gateway connects one network to another. A residential gateway typically employees something called Network Address Translation or NAT. In fact, you will often see your router referred to as a NAT device. The gateway is the only piece of hardware on your home network that has a "real" IP address accessible from the internet. NAT maps this IP address to the private IP address given to your PC. It is generally true that if you have a NAT device between you and the internet, then your computer cannot accept requests from outside the NAT device (i.e. the internet). However, you can configure your gateway to use something called "Port Forwarding" where you tell the gateway to forward requests to a particular port on the gateway to a port on your PC.
EndPoints, Sockets, Ports
These three terms mean essentially the same thing. When a client program on one computer wants to communicate with a server program on another computer, the client program needs to know two things:
Firewalls
A firewall simply acts as a barrier between your computer and the network (either private or the internet). Technically, your gateway is acting as a firewall, since by default it doesn't allow any incoming connections directly to your computer. Windows ships with Windows Firewall and is turned on by default. You can configure rules to allow or disallow programs from using specific ports on your computer.
Most computer networks today including the Internet use TCP/IP. An IP address uniquely identifies each computer on a TCP/IP network. You may have noticed that your home computer has an IP address that is not exactly unique. This is because all computers that are connected to your home router make up your own "private" network. Since your network is private, no computers from outside your network will be communicating directly with your computer. Therefore all private networks use IP addresses in the 192.168.x.x range.
What you think of as your home router or modem is actually a combination of things.
It is a modem. A modem is responsible for converting the communications into a form that can be sent over telephone or cable wires.
It is a router. The router routes packets of data to the computers they are bound for.
It is a gateway. A gateway connects one network to another. A residential gateway typically employees something called Network Address Translation or NAT. In fact, you will often see your router referred to as a NAT device. The gateway is the only piece of hardware on your home network that has a "real" IP address accessible from the internet. NAT maps this IP address to the private IP address given to your PC. It is generally true that if you have a NAT device between you and the internet, then your computer cannot accept requests from outside the NAT device (i.e. the internet). However, you can configure your gateway to use something called "Port Forwarding" where you tell the gateway to forward requests to a particular port on the gateway to a port on your PC.
EndPoints, Sockets, Ports
These three terms mean essentially the same thing. When a client program on one computer wants to communicate with a server program on another computer, the client program needs to know two things:
- IP address of the computer the server program resides on.
- The number of the port that the server program is "listening" on.
Together, these two things are called an endpoint, socket, or just port.
DNS
Since IP addresses are hard to remember, they came up with the Domain Name System. This is simply a registry that relates a name with an IP address. When you type www.google.com into your browser, the router actually looks up what the IP address is for that name using what is called a DNS server. The DNS server is typically provided to you by the ISP. However, you can change this to whatever you want. Open DNS for example.
Firewalls
A firewall simply acts as a barrier between your computer and the network (either private or the internet). Technically, your gateway is acting as a firewall, since by default it doesn't allow any incoming connections directly to your computer. Windows ships with Windows Firewall and is turned on by default. You can configure rules to allow or disallow programs from using specific ports on your computer.
Wednesday, May 7, 2014
Add an existing solution to TFS 2013
This post assumes you have a TFS server configured.
First you will need to create a TFS project to hold your files.
First you will need to create a TFS project to hold your files.
- In Visual Studio 2013, Team Explorer, click the navigation drop down bar and select Projects and My Teams and then choose Add New Project. You may need to be a collection administrator to do this. Browse here https://<TFS Server>/tfs/<Collection Name>/_admin to add a user to this group.
- A wizard will appear that will walk you through all of the options.
- The most important option here (and the most difficult to understand) is choosing the process template. Essentially, you are choosing what application lifecycle management style you use while developing software. I chose Scrum because it's something that I'm interested in and it's the default choice.
- You'll also need to choose a version control system, Git or TFVC. With Git the repositories are stored locally and with TFVC, there is a single version of the truth on the server. TFVC seems more appropriate if you're going to have a full blown TFS server.
Next, add your solution to the new project.
- If you don't know your branching needs yet, then don't create them at this point. However, more than likely at some point, you will want to create branches. To prepare for this possibility always put your initial files into a folder called Main.
- Map the new project to a local workspace.
- In Source Control Explorer, right click the project, and choose New Folder and call it Main.
- Check in this new folder.
- In File Explorer, copy your code into the Main folder in your workspace.
- In VS, open your solution from the Main folder in your workspace.
- Right-click the solution, and choose Add Solution to Source Control.
- Then Check In everything and you're done.
Thursday, May 1, 2014
TFS Cache
The other day I connected to a test TFS server that was identical to the production TFS server using Visual Studio 2013. When I tried to connect back to the production TFS server, I got a 404 error. To fix the problem, I closed Visual Studio and cleared this folder:
C:\Users\<You>\AppData\Local\Microsoft\Team Foundation\5.0\Cache
C:\Users\<You>\AppData\Local\Microsoft\Team Foundation\5.0\Cache
Subscribe to:
Posts (Atom)