moving ms sql server

we needed to move an sql server… so we looked for space in our virtual environment… there was… but wth? moving is renaming… or isnt it? first it looked like it was, but secondly there were a few problems…

basiclly the sql server instance has the same name as the server… wrong!

sp_dropserver ‘old_name’
GO
sp_addserver ‘new_name’, local
GO

this statements change the instance name… following command returns the current instancename…

select @@SERVERNAME

and thats the history of renaming ms sql servers… funny…

deploying asp.net mvc

the goal of every application is to get deployed on a server or another computer. sometime its really easy and logic to do so and sometimes its easy and logic, but you really mess up…

first of all asp.net mvc needs some dlls in the GAC… but normally installing stuff on servers is not really the good way… goal should be, to install as less as possible, or at least good controlable… and in my case, its a windows server… so controlable is not really a word to describe it… but on the other hand, im just a developer and not a server admin… so i might be wrong…

to avoid installing stuff in the GAC for asp.net mvc, just simply add the dlls to the bin folder and voila… every thing is good 🙂 you need to add following dlls:

  • Microsoft.Web.Infrastructure
  • System.Web.Helpers
  • System.Web.Mvc
  • System.Web.Razor
  • System.Web.WebPages
  • System.Web.WebPages.Deployment
  • System.Web.WebPages.Razor

or just read http://drew-prog.blogspot.com/2011/01/how-to-deploy-aspnet-mvc-3-app-to-web.html

and it works… or lets say here ends the easy and logic part 🙂

in my case, it didnt work… why? we use nant to deploy out application and we do not publish the .config files. makes sence, because the web.config contains server information and is unique for a server… but the views folder has an own, mvc-based web.config and a packages.config, which might be used as well… so i or lets say the deploy script messed up 😛

asp.net username

need the username of the current user in an asp.net website? simple:

string username = User.Identity.Name.ToString();

ok it actually not the user name, but the domain user account name… works with windows authentification…

Html.EditorFor

creating html stuff with asp.net mvc i really easy… thanks to the htmlhelper class… for example to create a input box:

@Html.EditorFor(model => model.Name)

this line of code renders the <input>-tag, with set value, name… based on the models attribute… so if its a string it renders a textbox… it its a bool, it renders a checkbox… this checkbox is rendered a little bit special, because there is always a hidden filed set false… i think this is needed to return always a value for the checkbox, even if its not checked… sounds great, but the result must be checked differently:

active = (collection[<checkboxName>].Contains(“true”) ? true : false);

Its a really cool helper… but has a really big problem… Html.EditorFor is currently not able to set a class… there for desinging the input fields is hard… for a textbox it renders class=”text-box single-line”… so simply add these to your css file… works good, but with a company wide stylesheet its kinda crap…

asp.net mvc

at work i needed to create a new web frontend… and actually i am really disapointed with microsoft web framework asp.net… for me it is too random… ok i dont know how to do it correctly, but i am really confused with the 32452390918745 events, which will be called every postback (postback? never thought in java, that there might be different types of postback… and handlers…)… but yeah… did some application with asp.net and they all work… and are running… i think… 🙂

new project. new technology: asp.net mvc. i like it… the concept is as stated in the name: mvc… and actually i think it is really good implemented and totally included into visual studio… simple create a controller… based on it create views and of course use the model… the where is my model thing is for me not yet 100% clear… when using a external project/dll… is the dll the model? or is the dll only the functionality for the controller to fill the model? or is the model a wrapper around the dll? currently using a bit of all possibilities… works, but fareaway from perfect…

ms sql timeout

ok we had a problem on an application… it was really slow and sometimes it resulted in a sql timeout. so sql server(MSSQL 2008 R2) must be slow… no wasnt… network must be slow… no wasnt… app server must be slow… no wasnt… app must be slow… good point… but isnt…

after reading and debuging the sourcecode(code was not mine and coder is on vacation(as usual, when problems pop up…)) the slow sql statement was a view… running the view in the ms sql management studio: instant… hmm… wtf? after a few more tests we figured out, that the problem is based on the sql servers client, and a little bit of randomness…. running the statement on the sql server was instant… running it locally on a computer 23 seconds!.. running it on a virtual maschine, on the same computer… instant… wth? and always in ms sql management studio…

after a few more tries, we saw, that the result of the viw is unsorted… adding a “order by” resulted in the same process speed on all boxes… WTF? but yeah… its the damn solution…

X-UA-Compatible

i had a problem with my super simple asp.net site… designed in locally with style sheets and looked cool 🙂 but after putting it on the IIS7 it looked completly different… wtf? after trying everything, renaming stuff, reconfigure the IIS, swear a lot… i found:

<meta http-equiv=”X-UA-Compatible” content=”IE=100″ />

ok it didnt really help, put it is the solution… 🙂

the X-UA-Compatible defines the render version browser of given website… so if IE=7, every newer browser tries to render the website with the IE7 rendering mechanism… every older browser renders it with its own rendering mechanism… so if set to 100 the browser renders it with his mechanism… as long as Microsoft doesnt release the IE101, when i hopefully do not create html anymore… …

but the meta-tag was not the solution in my case… IIS7 stores the X-UA-Compatible localy for every application… which can be set on the IIS7 in the http-header… that was the solution 🙂

read more

format in visual studio

simply

Crtl+K, Ctrl+D

nant timestamp

i needed a datretime to backup my deployed applications. the goal was to store the backup in a datetime named folder, so its easy to find the last backup.

tryed it with datetime::now() and other datetime functions, but wasnt really satisfied and acutally the nant code was kinda unreadable… so googled it… and tstamp is the solution

 <tstamp property=”backup.datetime” pattern=”yyyyMMdd_HHmmss” />

creates the wished for property… well done 🙂

ms office docx format

currently working on a c# document creator. main goal is to create new word documents, based on a template and input data…

so had to read stuff about the docx format and figured out pretty quickly, that the format is xml based… cool… but its way more better…

just ads “.zip” to a word document and open it…

read more: http://msdn.microsoft.com/en-us/library/aa338205(v=office.12).aspx