Category Archives: VB.Net

Set Crystal Reports Datasource at Run-Time

If you have a database, you more than likely want to query it and present the data. Right? Well,the choice of many is to go for Crystal Reports. This is great for doing the simple things with little hastle at all and also doing the really complicated stuff without too much referring to a help manual either.

But what happens when you find that you have created dozens of them in your development environment and now need to move this to production? I had this trouble and started on the manual process of using the “Set Datasource Location…”, but why do the same action multiple times, because remember that you will have to do the same in reverse when you want to go back to developing. So I thought lets do this at run-time.

Continue reading

1 Comment

Filed under VB.Net

Handle access denied in ASP.Net using Global.asax

Due to the way ASP.net processes requests to display a page the user is denied access to, this needs to be entered in your Global.asax file.

In the example below, we get the failed status code and if this is equal to 401, then we clear the content and then forward the user to the Access Denied page.

Private Sub Application_EndRequest(ByVal sender As Object, ByVal e As EventArgs) 
	'if login failed then display user friendly error page
	If Response.StatusCode = 401Then
		Response.ClearContent()
		Server.Transfer("~/AccessDenied.aspx")
	End If
End Sub

This way, the user doesn't get a standard (not user friendly) debug message.

1 Comment

Filed under .Net, ASP.Net, Error handling, VB.Net

VB.Net function to save data

The following function allows saving data and handles any errors gracefully.

Continue reading

Leave a comment

Filed under .Net, VB.Net