Developing and Debugging Applications with Data Sources Across Domains

by Evan 22. March 2011 11:17

As a developer working mostly across multiple domains, I've found myself having to VPN in and out quite often in order to connect to different data sources. The first issue I dealt with was connecting to our TFS server while being VPN'd onto a domain. The work-around was simply right-clicking Visual Studio and selecting "Run As Administrator". This way I could connect to databases I have access to on a private domain along with our TFS server at the same time.

The next issue I had was debugging code that connected to data sources that needed Service Account credentials. Recently, I needed to create an SSIS package to connect to a data source that I did not have access to, however, I do have the service account credentials. One method of running the package was setting up a user/proxy in SSMS with the credentials and running the package as the proxy but this didn't allow me to debug locally.

The solution was using runas.exe to open Business Intelligence Dev Studio. This way I could run BIDS under the service account and access the data source locally! This helped dramtically in saving time debugging apps and allowed to run queries locally instead of RDP'ing onto other machines.

To run any app using the "runas" executable, first create a new shortcut and in the location box enter something similar to the following: 

C:\Windows\System32\runas.exe /netonly /user:SERVICE_ACCOUNT_USERNAME "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe"

where we replace SERVICE_ACCOUNT_USERNAME with your service account name and "C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\IDE\devenv.exe" with the location\filename of the app you'd like to run.

When you open the shortcut you'll get a command prompt asking for the service account password (I've removed the account name).

After entering the password the app will allow you to access secure data sources on the domain successfully. So far I've used this method with Visual Studio, SSMS and BIDS. A great tip for any developer who needs to work locally.

Cloning Slides including Images and Charts in PowerPoint presentations & Using Open XML SDK 2.0 Productivity Tool

by wenyuz 21. March 2011 12:37

Since Microsoft used Open XML as their document format for the office products since 2007. You can rename the file to a .zip file and then explore the content of the office. Programming against office files is now more of an XML manipulation. Unless you want to purchase additional controls such as Apose which is currently support to up to 2007, Open XML SDK productivity tool is definitely your best friend.

I was working on cloning slides for a complex slide deck this past a couple of weeks which I need to clone the content of the slide as well as charts and images. So I was looking through resources online and I found a couple of good resources such as http://www.prowareness.com/blog/?p=392 and also http://msdn.microsoft.com/en-us/library/dd469465(v=office.12).aspx. However the Chartspace cloning part did not work for me in Anand’s blog, and I couldn’t find any other good resources to clone the charts. In Anand’s blog, he uses the ExternalData in the chartspace which does not resolve in my code, and I also tried to get the node and set the ID as a work around, however it does not work either. The PowerPoint slide would run an error when you try to open the file and requests a repair, and after repair, the content is no longer valid. So as a work around, I used the Open XML SDK Productivity Tool.

Here is what you can do to generate the charts on the fly. In cloning the slides, you need to clone all aspects of the slide. If you have two charts in the slide, you would need to clone both of them for the slide to work, chartspace as well as the external embedded excel worksheet for each of the chart. When you open the slide in the Productivity Tool, you need to explore to the chart xml that you want to clone. Normally if there is only one slide, then you need to open the node under ppt/presentation.xml -> ppt/slides/slide1.xml -> /ppt/charts/chart1.xml. When you select /ppt/charts/chart1.xml, and then click Reflect Code. In the reflect code pane, you will be able to find the code that you would need to create the chart on the fly. It would include CreateChartPart(ChartPart part) function that would call something similar to these five lines of code. And of course you would need to include the rest of the functions in the reflect code pane that the CreateChartPart function calls. If you have multiple charts in the slide that you need to clone, then you would need to get the CreateChartPart function for the second chart as well. This only works if you are cloning the charts onto a separate slide. Because in openxml , charts are indexed within the slide, so you can use the same code in the previous slide including the indexing.

public void CreateChartPart(ChartPart part) {
ChartDrawingPart chartDrawingPart1 = part.AddNewPart("rId2");
GenerateChartDrawingPart1Content(chartDrawingPart1);
EmbeddedPackagePart embeddedPackagePart1 = part.AddNewPart("application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "rId1");
GenerateEmbeddedPackagePart1Content(embeddedPackagePart1);
GeneratePartContent(part); }

Here is the function to clone the charts, images and slides:

public static SlidePart CloneSlidePartWithImagesAndCharts(PresentationPart presentationPart, SlidePart slideTemplate) {
int i = presentationPart.SlideParts.Count(); //Create a new slide part in the presentation.
SlidePart newSlidePart = presentationPart.AddNewPart(”newSlide” + i);
i++; //Add the source slide content into the new slide.
newSlidePart.FeedData(slideTemplate.GetStream(FileMode.Open)); //Make sure the new slide references the proper slide layout.
newSlidePart.AddPart(slideTemplate.SlideLayoutPart, slideTemplate.GetIdOfPart(slideTemplate.SlideLayoutPart)); // copy the image parts
foreach (ImagePart ipart in slideTemplate.ImageParts) {
ImagePart newipart = newSlidePart.AddImagePart(ipart.ContentType, slideTemplate.GetIdOfPart(ipart));
newipart.FeedData(ipart.GetStream()); } // copy the chart parts
ChartPart cpart1 = slideTemplate.ChartParts.FirstOrDefault();
ChartPart newcpart1 = newSlidePart.AddNewPart(slideTemplate.GetIdOfPart(cpart1));
CreateChartPart(newcpart1);
newcpart1.ChartSpace.Save(); //Get the list of slide ids.
SlideIdList slideIdList = presentationPart.Presentation.SlideIdList; //Deternmine where to add the next slide (find max number of slides).
uint maxSlideId = 1;
SlideId prevSlideId = null;
foreach (SlideId slideId in slideIdList.ChildElements) {
if (slideId.Id > maxSlideId) {
maxSlideId = slideId.Id;
prevSlideId = slideId; } }
maxSlideId++; //Add the new slide at the end of the deck.
SlideId newSlideId = slideIdList.InsertAfter(new SlideId(), prevSlideId); //Make sure the id and relid are set appropriately.
newSlideId.Id = maxSlideId; newSlideId.RelationshipId = presentationPart.GetIdOfPart(newSlidePart);
newSlidePart.Slide.Save();
return newSlidePart; }

After you clone the slide, you probably would need to edit the chart data, one way to edit each of the chart series is to remove the series and then create the series on the fly. If you have a line chart, you can get the code for creating the linechart by browsing to the ChartSpace, then c:chart (Chart) -> c:linechart (LineChart) -> LineChartSeries, and click Reflect code. If there are multiple LineChartSeries, then you would need to get the code for all series. Most of the code for generating the LineChartSeries are very similar. You could consolidate the functions into one function, however, you would need to make sure that the index for each LineChartSeries is correct, if there are not correct, the slide would not work. You would need to modify the function to include the new data for the new charts on the fly at the GenerateLineChartSeries function. So here is how you can remove the series and then add a new series in it’s place. However, one draw-back for updating the chart series this way is that the backend xslx for each chart is not updated.

ChartPart ChartPart1 = Slide1.ChartParts.FirstOrDefault();
Drawing.Charts.Chart Chart1 = ChartPart1.ChartSpace.Descendants().First();
Drawing.Charts.LineChart LineChart1 = Chart1.Descendants().First();
Drawing.Charts.LineChartSeries ChartSeries1 = Chart1.Descendants().First();
LineChart1.RemoveChild(ChartSeries1);
Drawing.Charts.LineChartSeries NewChartSeries1 = GenerateLineChartSeries(); //You would need to modify the function to either take in parameters in the function call and then add in the data according.
LineChart1.AppendChild(NewChartSeries1);
ChartPart1.ChartSpace.Save();

Customer Service is Customer Retention

by Erin Piazza 21. March 2011 12:11

I don’t believe many companies start up their customer service departments thinking, “this will be a great way for us to listen and talk 1:1 with our customers, and give them a really positive experience with our brand.”


To be honest, I don’t really know how most companies determine when they need a customer service department—I assume it’s when their receptionist can no longer keep up with the number of calls or customer service type tasks on his or her list. Or, maybe if the founders of a company are extremely sure of themselves, a customer service “department” is set up from the beginning of the company, since they will be “going big” any day.


I started thinking about customer service this morning because I am a loyal T-Mobile customer, and I was not happy when I heard about the acquisition by AT&T. I’m already researching how to get out from under this behemoth, and how to avoid being another victim of AT&T’s notoriously high prices and bad customer service. I haven’t even experienced it yet and I’m already running away.


When I call T-Mobile, or walk in to their local store, I don’t feel like another sales opportunity—I feel like a challenge they are excited to solve, and have seen employees go to great lengths to do so. I’ve been delighted with the solutions I’ve been offered to challenges I’ve faced with my plan, service and phone.  


It seems like T-Mobile started their customer service department with the idea I gave in the first sentence of this post—how can we make our customer’s experience great, from all angles?


Have you ever remained loyal, or run away from a company PURELY based on your experience with their customer service department?
I would argue, to some degree, that providing customers with a great experience when they need help, is maybe the ultimate act of retention.

Why C# Coding Standards

by SteveW 21. March 2011 10:11

I wanted to follow a series of posts that deal with some fundamentals, but help the most when it comes to the larger picture. This can be as simple is how a variable is named, but goes as deep as Design Pattern philosophy. Sometimes it is very easy to go down a path that you only find out later, may not have been the best route, especially when someone else has to use your code. I would like to cover some of these areas and what I do to help guide me down the right path.

There are some practices I hold myself to.  The first is Coding Standards. We expect the .NET Framework to conform certain standards, so why shouldn’t we expect the same from ourselves. After all we are writing extensions to the .NET Framework. So the next person, who has to use our code, should expect it to behave as the rest of the .NET Framework. How we name our classes and properties can make a huge difference in communicating our intent. This also includes how certain tasks could or should be implemented and following some of the patterns within the .NET Framework.

This sounds easy, but takes a commitment to ensuring a standard and going back and fixing problem areas when the intent may not be as clear as possible. When the class name or property names do not illustrate the complete intent, you must ensure comments are sufficient. This prevents you or someone else from having to look at the source code and interpret the intent. Even if you are the single person using your code, I do not know how many times I have had to look at code I had written previously, and ask myself, “Did I write this?” Many times a simple comment can save time down the road.

One resource I have found useful many years ago is the dofactory.com. They have a great article on C# Coding Standards and Naming Conventions. This covers the Do’s and Don’ts of casing, styling and naming conventions. They also are a great resource for Design Patterns. I will cover, some of my favorite Design Patterns and which are commonly used within the .NET Framework itself.

My morning cup of Joe doesn't taste as good.

by BryanB 17. March 2011 19:05

While I'm a business person, in the same regard I'm a developer at heart (in particular I was born and raised as a MS developer). Ten plus years ago, every day I'd spend a good 30 minutes each morning "getting up to speed" based on what was on MSDN's site. It was my coffee-time if you will. It was great everything was laid out super clear and up front.

All of the latest stuff was out there; I could easily find the latest download and read the latest article. I felt I like was the most informed developer on the planet and MSDN was the reason. Literally every day there was a high likelihood there was something new and update... a download, article, some library, demo, ...

I really have to say that I'm little less impressed lately, and it seems like its only gotten worse over the last year or two. I was hoping it was a fad where it would only last for a month or two and then the world would be right again, unfortunately it never righted itself.

So I went to MSDN today and on the home page below is a screenshot of the "News" section of the home page... don't even get me started on how the true front page has nothing news oriented, for a number of days I didn't even realize there was a news tab and I totally thought my life as an informed dev sucked.

However I eventually found the page and you can see the below results from going to it today. So here's what I found:
1. The big area (and coincidently the most recent piece) talked about 2 upcoming conferences and a book about Azure.

Unfortunately that's where it stopped. And I am only talking about stuff above the fold, I didn't even check below the fold. So let's look at the results other than the conferences and a book.
1. An article about MVC3 and MEF - 11/19/2010 - seriously an article from 4 months ago (is in maybe one of the most prominent spots on MSDN's NEWS homepage, how is an article 4 months ago NEWS)
2. An article from 1/15/2011
3. An article from 1/1/2011
4. An article from 1/18/2011
5. An article from 1/20/2011
6. An article from 2/15/2011
7. An article from 12/13/2010

So apparently there was a lot (4) news worthy items that happened in January and other than 1 article in Feb (which looks like it might be on the same topic as the article from Jan) its time to dig back to Dec. of 2010...

Really? There's nothing cool that's come out that people should know about over the last 2 MONTHS? In theory, on the home page for MSDN (or sort of home page), there's nothing that's come out other than 2 conferences and a book. I know things move at a little different pace at MS compared to 10 years ago, but certainly not that slow. If this was 10-15 years ago on the MSDN site 50% of the content on this same page (above the fold) would be from this month.

So this is plea to whomever manages the MSDN site... please think hard about what MSDN meant for a lot of us developers quite a while ago and realize the great thing about a website is you can always change it to make it better.

 

Tags:

Randomness

Parameter Passing in SSIS

by JasonR 15. March 2011 14:50

I had to set up an SSIS package that inserted data into a log, grab that logID and pass it to all of the sub tasks so they can use that LogID.

I am new to SSIS packages and had to do a lot of reading to come up with how I was going to create an SSIS Package, Define a package variable, then pass that variable to a task. I set up a simple proof of concept to test my ideas.

First I Opened VS, and created a new Integrated Service Project. If you have a hard time finding it, it’s Project Types: Business Intelligence Project, you may need to install this from your SQL installation.

Next I Clicked on Tools->Other Windows->Variables. Making sure I have the SSIS Package I want to work with selected and in the open window I clicked on the icon for new variable. This was important because your variable scope can be pointed to a different project or at the task level if you aren’t paying attrition.

I gave it a common name, and set the Data Type to Object. This is set to object because I had an issue passing int32 values. I’ll talk about it below.

Now in my Control Flow I opened up my “toolbar” and dropped two Execute SQL tasks, I double clicked on the first one. Because this one will pass the ID to my variable I need to set the ResultSet to ‘single row’ then I am using an OLE DB connection, and put my localHost for the server.

Then I clicked on the SQL Statement ellipses and pasted in a very simple statement “select 8 as Test” this is just so I pass a value, in my real solution I had a bunch of sql code and ened it with “select IDENT_CURRENT('log.TaskRun') as TaskRunID” .

Now I have to bind “test” in my example or “TaskRunID” in my second example to the variable. I do this in the “Result Set” tab. I simply click “Add” (if you do not see add you did not set a value for “ResultSet”) For ResultName, this is where I put “Test” or “TaskRunID” for Varable Name it will look like User::<name>. Click ok and open the next Task.

For the second Execute sql task you will fill out the same information as before this time with a new SQL Statement.  For simple sake I put this
Declare @temp numeric
set @temp = ?
insert into log.taskrunlog (message) values (@temp)

Here I am jut inserting my value into the database, to show I did something.  Things to note is that I am declaring my temp as numeric, this was the only int style choice I could find. Also note the “?” this is used to denote variable in SSIS.  In my simple example I could replace @temp with the ? and only have one line of code, but if I wanted to reuse the ? I must put it in a variable. If I had 3 parameters then each ? will refer to a different parameter.

Next  lets click on the Parameter Mapping tab and click “add” from here you are going to select the variable name from the drop down user::<name> this is an input, data type is Numeric, next it very important Parameter Name is 0. If you have a list of them the next will be 1 etc. This allows the ? to work correctly.

From here you can right click and ‘execute task or f5 or click the green arrow. In my case I had to save it to the server first before I could execute my package, I can do that by file->save copy of testVarable.dtsx as…

From here I was able to create a task and execute it from sql, I’ll be showing that part next week.

Back to Basics in Visual Studio 2010

by johnb 10. March 2011 17:32

Have you ever wondered what those icons are on the top right of the toolbar? Don’t be afraid. Go ahead and click and see what happens. 

  

These icon’s are very helpful. For instance if you accidentally closed out “Solution Explorer” one of these icons can help you open it back up. To find out which one, point your cursor on top of the icon’s and wait a second. A help dialogue box pops up that states what the icon is. Plus it will give you short cut keys. 

 

Pretty cool, huh? After experimenting with the icons, now you can layout your custom workspace to maximize the efficiency of development work. 

 

LinkedIn Launches Social Media News Site

by andreas 10. March 2011 15:07

A recent NY Times article by Audrey Watters highlights LinkedIn’s new social media news site for professionals, LinkedIn Today. Combining the features you love about your favorite online newspaper with the aspects of social media, the site offers headlines and links to popular stories within certain industries and within your LinkedIn network. You’ll also be able to see what your contacts are reading and save articles to read later. I must say, it looks pretty cool and this early in the game, I’m a fan.

Read Audrey Watters’ article here.

Check out LinkedIn’s official announcement here.

TFS - Saving Time and Avoiding Headaches with Excel

by charlesd 8. March 2011 09:56

Whenever I need to add or edit items in Team Foundation Server, doing so in TFS itself can be a pain, especially if there are multiple items that need to be updated.  After working with TFS for a while, I’ve found a way to streamline my work by using the Excel feature. 

For me, I find it’s super helpful to see all items in an organized list and being able to edit fields on the fly in one spreadsheet makes working with TFS so much easier.

I have created a quick guide that goes through creating and editing TFS items in Excel:

                                                                                                       

Create New Items in Bulk

1.       Ensure you have Work Item Tracking selected in your toolbar by right-clicking in the toolbar and selecting Work Item Tracking.

2.       In the toolbar, click the New Work Item dropdown and select New Work Items with Microsoft Excel.

3.       A new Excel workbook will open with a standard blank table for you to enter field values.

4.       From here, every row is an item and you may add in as many as you’d like.

Note: You can select any variation of work item types (User Story, Task, Bug, etc.) in the Excel.  Even if a work item you selected isn’t associated to a field column, that column will not be editable for that specific row.

Add Field ColumnsIf you want to add more fields, you may do so by adding more columns

5.       Select the Team tab at the top so open the Ream ribbon.

6.       In the Work Items section, select Choose Columns.

7.       From here, you may select the desired fields you would like to display in the columns by moving the fields from the Available columns to the Selected columns.

8.       Click OK to add the columns.

Publish Work ItemsHere is where you will be saving your updates and complete create your work items in TFS

9.       In the Team ribbon, under Work Items, select Publish.

10.   All updates will be made and you will see the IDs are instantly created.

Edit Items in Bulk

11.   In your TFS query, select multiple items that you would like to make updates to.

12.   Right-click in the list and select Open Selection in Microsoft Excel.

13.   Just like going to create new items, this will take you directly into an Excel workbook where you can make updates to the work items you selected.

The Machine is Us/ing Us

by ChrisR 7. March 2011 17:31

This simple but amazing video walks through the evolution of the web from it's early days to today. Everytime I see this it gets me excited to create something. Take a look...I'm sure you'll like it: You can also download a higher resolution copy below: Windows Media File (55 MB) | Quicktime File (96 MB)

Tag cloud