Dailycode.info

Short solution for short problems

How to kill a process on an other machine?

Found a good solution that does the trick! It takes only 9 line of code!

private void btnKillProcess_Click(object sender, EventArgs e)

{

ManagementScope scope = new ManagementScope(@"\\MyPCName\root\cimv2");

scope.Connect();

ObjectQuery query = new ObjectQuery("SELECT * FROM Win32_Process WHERE Name = process.exe'");

ManagementObjectSearcher searcher = new ManagementObjectSearcher(scope, query);

ManagementObjectCollection objectCollection = searcher.Get();

foreach(ManagementObject managementObject in objectCollection)

{

managementObject.InvokeMethod("Terminate", null);

}

}

Source: http://weblogs.asp.net/stanleygu/archive/2010/03/31/tip-13-kill-a-process-from-local-to-remote.aspx


Self tracking entity update not working or not purged to the database

If for some reason (Working with decoupled layers, eg. WCF) the update is not purged to the database by using self tracking entities and the entity framework, you can try this to solve it:

in stead of writing this code:

deploySettings.MarkAsModified();

deploySettings.Modified = DateTime.Now;

deploySettings.ModifiedBy = userName;

deploySettings.UpdCount = deploySettings.UpdCount + 1;

deploySettings.AcceptChanges();

 

Write the code like this:

deploySettings.MarkAsModified();

deploySettings.Modified =DateTime.Now;

deploySettings.ModifiedBy = userName;

deploySettings.UpdCount = deploySettings.UpdCount + 1;

ents.GP_MES_Deploy.ApplyChanges(deploySettings);

 

Last off course save the changes

ents.SaveChanges();

In my case I was sending over my self tracking entities to iOS over SOAP. The self tracking was then not working. So the context did not find the changes. 

 

 

 


Entity frame work with self tracking entities database changes.

There are many ways to implement the entity framework. I chose to add a link to the template in a different project. This implementation can be found here.

Now this article doesn’t describe in detail what to do when the database changes. This can be a very pain full operation if you have to figure it out yourself. That’s why I wrote this post.

In this case I chose to change an existing database table and add a new table to the database.

I divided the solution in 3 layers, the database layer, a process layer and a GUI. In between you’ll find the entities going from top to bottom. So no use of DTO or any kind of mapping.

 

The edmx model is located in the DataLayer. Also the generated tt files for the self-tracking entities is located there.  In the CMDBProcessLayer  I added the context as link and in the CMDBentities project I added the self-tracking objects as linked files.

Let go to the update process.

Step 1 is off course update the database.

Step 2: Remove the linked files to the entities and the context.

 

 

Step 3: Update the database model (edmx file)

before:

 

after: (Do not forget to save the model, else you could get problems creating the code generation items)

 

Step 4: Delete the old tt files in the DataLayer

 

Step 5: Generate new tt files

 

Step 6: Turn off code generation on the entity model.tt file

 

Step 7: Delete all remaining file generated by the entities.tt file:

 

Stap 8: repeat step 6 and 7 for the context.tt file

 

Step 9: Add the Entity.tt file to your entities shared projects. (If you do not see the files, choose 'All Files' in the file filter box on your lower right.)

 

Step 10: add the context.tt file as linked file to the process layer

 

Step 11 (Last step): Change the namespace of context.tt file to the namespace of the shared entities project.

 

Now you can build and you have the new data structure.

 


SPF CREATE DATABASE permission denied in database 'master'

While installing SPF on I kept gettings this error: CREATE DATABASE permission denied in database 'master'.

So I was giving the user sufficient rights tfor this, but still I got the error. After some googling around, I found out that the user who is running the setup need to have these rights, not the user you provide to the wizard.

So after I gave my user sufficient rights it worked. Hope some people will be helped with this!