Skip to content


sql management studio Timeout expired

sql management studio Timeout expired. The timeout period elapsed prior to completion of the operation or the server is not responding.

This can be a pain when you want to make changes that affect tables with large quantities of data

There are three location syou will need to check

In managament studio

1.
Tools > options > Query Execution > SQL server > General

verify Execution time-out. for unlimited timeout set to 0

2.
Tools > options > Designers > Table and Database designers

verify Transaction time-out. for unlimited timeout set to 0

3.
when you first make the database connection, in the connection window popup, click on “options”. select the “connection properties” tab and verify the “connection time-out” and “execution time-out” are set to your liking. once again 0 is unlimited

Posted in Uncategorized.


CSS – Centre element to parent / page

Two ways to centre horizontally on your web page

using min-width and max-width. Use this when you need your element to be a fixed height from the top of the window

using absolute and width. use this when you want to be dead centre of the window

Posted in Uncategorized.


textarea highlight / select and scroll to text – cross browser – pure javascript

I wanted a cross browser solution to select and highlight text within a text area. Trawling the internet yielded some partial solutions.

But I could not find one that scrolled to the correct location without a hack or some jiggery pockery

So I took what others had done and made it better. This is a cross browser solution that works in IE, firefox and chrome

the code pure javascript

Uasage

this is how to use it

how it works

Essentially, it uses the textareas full height (totalHeight), and the total number of new lines (totalLines). From this we can determine the line height

Now that we have the number of lines and the line height all we need now is to determine which line the selected text is on. To find this we take the total number of lines in the textare and deduct the number of new lines after our selected text

Finally to get the scroll to position we multiply the line number by the line position of the selected text

Posted in Development, HTML, javascript, jQuery.


Configure ASP.NET WebAPI to default to JSON

you’ll need to add newtonsoft json to your project.

Application start, add the initialisation code

Now the code itself.

Posted in Uncategorized.


WhatsApp – network ports TCP/UDP

To Enable WhatsApp open these ports TCP/UDP

I had an issue with users trying to make video calls on WhatsApp, they simply couldn’t, so i spent some time on this and can safely say if you open these ports, WhatsApp will work for Data messages, Voice and Video calls.

  • TCP (4244, 5222, 5223, 5242) outbound
  • UDP (3478, 45395) send and recieve

voila!

Posted in Uncategorized.


HTML 5 ASP.NET Drag n Drop IE Chrome Firefox

drag and drop, cross browser support in asp.net

part of a project involved allowing a user to select from a list of 200+ items, and it needed to be easy. So, we decided to provide users with a drag and drop facility

Drag and drop has been around for quite some time, and its a little tricky to get it right. I’m going to show you the basics that i used to enable a drag and drop between lists

What are we after?

we want draggable lists that will do the following

  • Two lists
  • drag and drop
  • support multi select
  • support re order of list items

The end result

this is what the HTML will look like once the page has rendered, go ahead, give it a try. Try selecting multiple items then dragging them over

as you play around with the drag and drop, monitor your browser console to view the events that are firing

notice that when you change the selected fields the text area displays a comma separated list of selected items

Filter list
Choice fields

  • Name 1
  • Name 2
  • Name 3
  • Name 4
  • Name 5
  • Name 6
  • Name 7
  Selected fields

  • Name 8
  • Name 9
  • Name 10
  • Name 11
  • Name 12
  • Name 13
  • Name 14

 

This drag and drop is tied together with just 4 javascript functions, tied to the browser drag events

  • handleStartDrag()
  • handleDragEnter()
  • handleDragOver()
  • handleDropped()

there are ancillary functions that bind events and respond to the filter

  • fltrChanged()
  • UpdatehiddenFields()
  • bindUIactions()

How its done

In a nutshell

The rendered HTML

So whats going on ?

Well a few things are happening here, CSS is styling our stuff. ASP.NET is loading the repeater and generating our “li” elements for the un-ordered lists. And jQuery is doing the rest

the keys points to note here are:

  • the classes used {ctlDrop, ctlDrag} (for CSS and more importantly jQuery hooks)
  • the draggable attribute on the items tell the browser these are allowed to be dragged
  • the use if ID‘s and Data- attributes as hooks for our functionality

how it works

first up i will say you have to do a few inexplicable things to get drag and drop working, but its a given, just do it and don’t ask, or you’ll simply lose your mind like many other techies who ask the “why did they do that?” question. like me

1. enable jQuery to support passing a payload across drag n drop.
2. declare a variable in your class to hold the last entered item that the drag action has entered.

The singleton script layout looks like this

 

The Code

Loading the form

The code infront

jumping straight in, we need two lists, driven by some data source. Here is how we load the lists, using .net repeaters

Notice we have a hidden field in the right hand column, this will be used to stored the selected values, as the selection changes

Code Behind – the repeater code

On our data bind we add list items to the list, and some information to the each list item. Class, draggable, data-fieldName, data-ordinal.

jQuery – the ancillary functions

bindUIactions()

We will bind to the dragover and the drop event on the elements with class ctlDrop

We will bind to the dragstart, dragenter, drop and click events of the elements with class ctlDrag

Finally we will bind to the txtfltr element so we can filter our list

UpdateHiddenFields()

handling the collecting of the selected items into a comma separated list is relatively simple, and this function will be called from the end of the drop event

jQuery – The Drag and Drop routines

handleStartDrag()

The start drag routine, a must have to set the sllowed effect property, this is searchable on the drop if you need to.

handleDragOver()

The drag over routine, this is another must have, without this, obscurely no draggable item will drop. Don’t ask just do

handleDragEnter()

The drag enter routine, this is required because internet explorer doesn’t correctly record which element the drop occurs over, so here we record the last entered element before the drop. And thus we have cross browser compatibility

handleDropped()

The drop routine, this is where all of the hard work is done. If you are a public facing website you might want to add screening of the mime type that is dropped, just incase its not what you are expecting. I’m not doing that here, our project was internal

 

the javascript file is available for download here dragndrop

the CSS is available for download here dragndrop CSS

Posted in .NET, ASP, HTML, jQuery, VB.


Windows.Forms Settings : Auto Save state (size and position) of all my Forms

We will cover three topics in one

  • Using a single settings variable to save ever forms window state
  • Base class inheritance in winforms
  • Data contracts and JSON

In a nutshell, we will serialise and deserialise into a strongly typed custom settings class to and from JSON to store out our windows forms window states, in a settings variable in the project, using a custom settings class that is present in a baseClass that every form within your project will inherit from

What are data contracts

A data contract is essentially a simple way of serialising a class into a string for storage and/or transport

In simple terms, when you mark a class as a data contract you are telling .NET that this class will have properties that can be stored as a string (in our case serialised to JSON).

this is how to mark a class as a data contract

And members that you would like to store in your JSON should be marked as data members like so

How do data contracts work with JSON?

A long time ago I wrote a generic serialiser/deserialiser to convert datacontract classes to and from JSON, this is the code

we are going to reference these function later in this article

How do we use inheritance in winforms

Windows forms classes that you are exposed to are essentially partial classes. If you have a project open that contains a Windows.Forms.Form, then unhide all documents and take a look at the difference between the code behind the form that you see and the designer generated code. The file names will have this structure

  • frmName.vb
  • frmName.designer.vb

Partial classes are a really nice way to extend the reach of a single class, but separate the code file

So, create a baseclass ready to be inherited by all of your windows forms

  • frmName.vb
  • frmName.designer.vb
  • BaseForm.vb

create the project settings property

next we create our custom project settings property “FormSizesAndLocations”

projectsettings

The custom settings class

we need our settings class to be able to do the following

  • read the settings from the config
  • save a forms window state to the config
  • name, width, height, x position, y position, maximised, minimised

here is our custom settings class for saving window state and reading window state, note the data contract attribute and the data member attributes to those properties we want to persist

The BasePage class that will do all the work

Now lets create a base page class, in this class we will put the logic to handle the position save and load of any form that then inherits this class

Rather than describe the code, you should really be able to understand it, so lets dive into the forms base class

And there you have it

Posted in .NET, Development, optimisation, VB.


Visual Studio – file properties – Build action

The various build action options

  • None: The file is not included in the project output group and is not compiled in the build process. An example is a text file that contains documentation, such as a Readme file.
  • Compile: The file is compiled into the build output. This setting is used for code files.
  • Content: Allows you to retrieve a file (in same dir as assembly) as a stream via Application.GetContentStream( uri ). For this method to work, it needs a AssemblyAssociatedContentFile custom attribute which VS graciously adds when you mark a file as “Content”
  • Embedded resource: embeds the file in an exclusive assembly manifest resource.
  • Resource (wpf only): embeds the file in a shared (by all files in the assembly with similar setting) assembly manifest resource named AppName.g.resources.
  • Page (wpf only): Used to compile a xaml file into baml. The baml is then embedded with the same technique as Resource (i.e. available as `AppName.g.resources)
  • ApplicationDefinition (wpf only): Mark the XAML/class file that defines your application. You specify the code-behind with the x:Class=”Namespace.ClassName” and set the startup form/page with StartupUri=”Window1.xaml”
  • SplashScreen (wpf only): An image that is marked as SplashScreen is shown automatically when an WPF application loads, and then fades
  • DesignData: Compiles xaml viewmodels so that usercontrols can be previewed with sample data in visual studio (uses mock types)
  • DesignDataWithDesignTimeCreatableTypes: Compiles xaml viewmodels so that usercontrols can be previewed with sample data in visual studio (uses actual types)
  • EntityDeploy: (Entity Framework): used to deploy the Entity Framework artifacts
  • CodeAnalysisDictionary: A xml file containing custom word dictionary for spelling rules

Origin : Stack Overflow

Posted in Uncategorized.


Excel Automation unable to open file

Cannot access the file make sure it exists and you have permission

I was receiving this error while I was implementing excel automation in a WCF service

Oddly all you have to do is create two folders, or one if you are running a 32BIT OS

64 bit

·Windows 2008 Server x64

Please make this folder.

C:\Windows\SysWOW64\config\systemprofile\Desktop

32 bit

·Windows 2008 Server x86

Please make this folder.

C:\Windows\System32\config\systemprofile\Desktop

So it would seem that a folder named “Desktop” is required in the systemprofile folder in order that excel automation can open files

Posted in Uncategorized.


Windows time out of sync (Hyper V)

Time server working but time is wrong

If you have ever come across a situation where your Domain Controller (DC) is syncing properly to its ntp source, but the time is incorrect, the likelihood is that you are operating a virtual server environment and your Primary Domain Controller (PDC) is a virtual machine.

The issue

This Microsoft article Virtual Active Directory Domain Controller explains clearly, uner the heading “Time Service” that you must remove the sync between the virtual machine and the host.

I was late for a gym session because of this

Time service
——————————————————————————–
For virtual machines that are configured as domain controllers, it is recommended that you disable time synchronization between the host system and guest operating system acting as a domain controller. This enables your guest domain controller to synchronize time from the domain hierarchy.

To disable the Hyper-V time synchronization provider, shut down the VM and clear the Time synchronization check box under Integration Services

Thinking about it, this makes perfect sense. With the option ticked, the PDC is set to get its time from the host, and if the host is part of the domain, it in turn is set to get its time from the nearest DC, who also in turn get their time from the PDC. A cyclic loop where no one gets the time from an external ntp source.

To configure the time server please visit here https://blogs.technet.microsoft.com/nepapfe/2013/03/01/its-simple-time-configuration-in-active-directory/

Un-tick the “Time synchrnoization” option from hyper v manager
hyperv-time-synchronization

Posted in Infrastructure.