Author Archives: Josh

Encrypting and Decrypting Sections of a Web.config with PowerShell

In this post I will show you how to Encrypt and Decrypt Sections of a Web.config file.

This function will encrypt a sections of a web.config file.

function Encrypt-ConfigurationSection([int] $id, [string] $app, [string] $section, [string] $version){
$currentDirectory = (Get-Location)
Set-Location "C:\windows\Microsoft.Net\Framework\$version\"
.\aspnet_regiis.exe -pe $section -app $app -site $id -prov "RsaProtectedConfigurationProvider"
Set-Location $currentDirectory
}

Example call

Encrypt-ConfigurationSection 1 ‘/WebApplication1’ ‘connectionStrings’ ‘v4.0.30319’

This function will decrypt a sections of a web.config file.

function Decrypt-ConfigurationSection([int] $id, [string] $app, [string] $section, [string] $version){
$currentDirectory = (Get-Location)
Set-Location "C:\windows\Microsoft.Net\Framework\$version\"
.\aspnet_regiis.exe -pd $section -app $app -site $id
Set-Location $currentDirectory
}

Example Call

Decrypt-ConfigurationSection 1 ‘/WebApplication1’ ‘connectionStrings’ ‘v4.0.30319’

Now, if you look at the functions you will notice that there is a $version variable. The $version variable is important. This is because if you are working with an ASP.net web application that uses an Application Pool with a Managed Runtime Version of v2.0, then you want to be using the aspnet_regiis application for that version. The same goes for Applications that use and Application Pool with a Managed Runtime Version of v4.0.

From the blog joshjoubert » CS@Worcester by Josh and used with permission of the author. All other rights reserved by the author.

Encrypting and Decrypting Sections of a Web.config with PowerShell

In this post I will show you how to Encrypt and Decrypt Sections of a Web.config file.

This function will encrypt a sections of a web.config file.

function Encrypt-ConfigurationSection([int] $id, [string] $app, [string] $section, [string] $version){
$currentDirectory = (Get-Location)
Set-Location "C:\windows\Microsoft.Net\Framework\$version\"
.\aspnet_regiis.exe -pe $section -app $app -site $id -prov "RsaProtectedConfigurationProvider"
Set-Location $currentDirectory
}

Example call

Encrypt-ConfigurationSection 1 ‘/WebApplication1’ ‘connectionStrings’ ‘v4.0.30319’

This function will decrypt a sections of a web.config file.

function Decrypt-ConfigurationSection([int] $id, [string] $app, [string] $section, [string] $version){
$currentDirectory = (Get-Location)
Set-Location "C:\windows\Microsoft.Net\Framework\$version\"
.\aspnet_regiis.exe -pd $section -app $app -site $id
Set-Location $currentDirectory
}

Example Call

Decrypt-ConfigurationSection 1 ‘/WebApplication1’ ‘connectionStrings’ ‘v4.0.30319’

Now, if you look at the functions you will notice that there is a $version variable. The $version variable is important. This is because if you are working with an ASP.net web application that uses an Application Pool with a Managed Runtime Version of v2.0, then you want to be using the aspnet_regiis application for that version. The same goes for Applications that use and Application Pool with a Managed Runtime Version of v4.0.

From the blog joshjoubert » CS@Worcester by Josh and used with permission of the author. All other rights reserved by the author.

SQL Server Database Projects – Part 3 Publishing

OK, I the post I will be discussing how to publish (deploy) a data-tier application.

This process, in general, is quite easy. 

What you will do is right-click on the data-tier application.

Once the sub-menu appears you will select publish.  Now, in the publish form that appears you will notice quite a few options.  I will briefly go through some of the more important ones.

You will notice a textbox with a title of “Target database connection.”  This where you will pick the location to where you want the database to be deploy or the update to applied.

Then there is a textbox with a title of “Database name.” This is the name of the database to create or update.

Publish script is the name of SQL script that contains all of your changes.

Now, if you look towards the bottom of the form you will notice a checkbox that has a title of “Register as a Data-tier Application.” So, now you might be asking yourself.

What does register as a data-tier application mean? 

Well, what is means is, when you deploy the database, the database will be registered with the SQL Server.  Now what does SQL Server do with data-tier applications that is different from none data-tier applications?  Well for starts it adds a record to the sysdac_instances_internal table in the MSDB system database.  it will also monitor any schema changes that occur to the database outside of dacpac deployments.

Now, if you check that box, the line just below will now become active. Now, if you check this box as well, and the database has changed outside of dacpac deployments you will get an error stating that the database has drifted from the register version.

you will notice a button that is labeled Advanced… this opens you a form with a large list of options for the database deployment. the following link is a good place to go to find information out about the options in the form

SQLPackage.exe (a Microsoft executable for command line deployments (publishes) of dacpacs.

From the blog joshjoubert » CS@Worcester by Josh and used with permission of the author. All other rights reserved by the author.

SQL Server Database Projects – Part 3 Publishing

OK, I the post I will be discussing how to publish (deploy) a data-tier application.

This process, in general, is quite easy. 

What you will do is right-click on the data-tier application.

Once the sub-menu appears you will select publish.  Now, in the publish form that appears you will notice quite a few options.  I will briefly go through some of the more important ones.

You will notice a textbox with a title of “Target database connection.”  This where you will pick the location to where you want the database to be deploy or the update to applied.

Then there is a textbox with a title of “Database name.” This is the name of the database to create or update.

Publish script is the name of SQL script that contains all of your changes.

Now, if you look towards the bottom of the form you will notice a checkbox that has a title of “Register as a Data-tier Application.” So, now you might be asking yourself.

What does register as a data-tier application mean? 

Well, what is means is, when you deploy the database, the database will be registered with the SQL Server.  Now what does SQL Server do with data-tier applications that is different from none data-tier applications?  Well for starts it adds a record to the sysdac_instances_internal table in the MSDB system database.  it will also monitor any schema changes that occur to the database outside of dacpac deployments.

Now, if you check that box, the line just below will now become active. Now, if you check this box as well, and the database has changed outside of dacpac deployments you will get an error stating that the database has drifted from the register version.

you will notice a button that is labeled Advanced… this opens you a form with a large list of options for the database deployment. the following link is a good place to go to find information out about the options in the form

SQLPackage.exe (a Microsoft executable for command line deployments (publishes) of dacpacs.

From the blog joshjoubert » CS@Worcester by Josh and used with permission of the author. All other rights reserved by the author.

SQL Server Database Projects – Part.2

This is a continuation of my previous blog SQL Server Database Projects – Part.1.

In this post I will be discussing how to create a SQL Server Database Project. I will also be discussing the a few of the files types that you can use with in the project.

Now let’s get started

To start, you will need to open Visual Studio 2012.

Once you have Visual Studio open you will need to select New Project

VisualStudioStartPage

You will get a dialog like the open below.

 SqlProjectDialog

In the Dialog you will select SQL Server > SQL Server Database Project.  Once you have done that you will need to give you project a name after click OK.

Now you should have a screen that looks like the one below.

ProjectCreated

From here you have the option of adding files that you will need for you database or if you have a database that you want to import, then you can import it.

First things first.  We need to create a table. in order to create a table you will need to right-click on the project then select add > New Item

you will be presented with a dialog that has a a large number of different files.  Scroll down until you find one labeled Table. Select it and then give your table a name.

After you have done that your screen should look similar to the one below.

DBTable

From here it is just like creating a table through SQL Server Management Studio. you add columns, set a primary key, create unique keys, add constraints, anything that you can do with SSMS (SQL Server Management Studio) you can do here.

 

Well, that’s it for now.  My next post will go through publishing your database.

From the blog joshjoubert » CS@Worcester by Josh and used with permission of the author. All other rights reserved by the author.

SQL Server Database Projects – Part.2

This is a continuation of my previous blog SQL Server Database Projects – Part.1.

In this post I will be discussing how to create a SQL Server Database Project. I will also be discussing the a few of the files types that you can use with in the project.

Now let’s get started

To start, you will need to open Visual Studio 2012.

Once you have Visual Studio open you will need to select New Project

VisualStudioStartPage

You will get a dialog like the open below.

 SqlProjectDialog

In the Dialog you will select SQL Server > SQL Server Database Project.  Once you have done that you will need to give you project a name after click OK.

Now you should have a screen that looks like the one below.

ProjectCreated

From here you have the option of adding files that you will need for you database or if you have a database that you want to import, then you can import it.

First things first.  We need to create a table. in order to create a table you will need to right-click on the project then select add > New Item

you will be presented with a dialog that has a a large number of different files.  Scroll down until you find one labeled Table. Select it and then give your table a name.

After you have done that your screen should look similar to the one below.

DBTable

From here it is just like creating a table through SQL Server Management Studio. you add columns, set a primary key, create unique keys, add constraints, anything that you can do with SSMS (SQL Server Management Studio) you can do here.

 

Well, that’s it for now.  My next post will go through publishing your database.

From the blog joshjoubert » CS@Worcester by Josh and used with permission of the author. All other rights reserved by the author.

SQL Server Database Projects – Part.1

What is SQL Server Database Project?

NOTE: This post pertains to Visual Studio 2012.

A SQL Server Database Project is a Visual Studio project type that allows you to create, edit and publish a database to SQL Server.   These projects create a file type with an extension of .dacpac.  What these file are in actuality is a set of SQL scripts that are executed on a Microsoft SQL Server.  If the database does not yet exist on the server when the .dacpac is run it will create the database, otherwise the database will be updated.

One of the good things about using this project is that you can save the project into your source control tool (TFS, Subversion, etc.) which allows for the tracking of changes.  Also, you can set a property when you build the project that will allow you to register the database as a data-tier application.  Now, what this does is it creates an entry in the MSDB.dbo.sysdac_instances_internal database with a version number, this version number can be changed in the project as well.  This is done by going to your projects properties and selecting “Project Settings” and the clicking the “Properties” button under “Output types.” This will open up a window that has a version number in it.

 

In my next post I will go over actually creating and deploying a project.

From the blog joshjoubert » CS@Worcester by Josh and used with permission of the author. All other rights reserved by the author.

SQL Server Database Projects – Part.1

What is SQL Server Database Project?

NOTE: This post pertains to Visual Studio 2012.

A SQL Server Database Project is a Visual Studio project type that allows you to create, edit and publish a database to SQL Server.   These projects create a file type with an extension of .dacpac.  What these file are in actuality is a set of SQL scripts that are executed on a Microsoft SQL Server.  If the database does not yet exist on the server when the .dacpac is run it will create the database, otherwise the database will be updated.

One of the good things about using this project is that you can save the project into your source control tool (TFS, Subversion, etc.) which allows for the tracking of changes.  Also, you can set a property when you build the project that will allow you to register the database as a data-tier application.  Now, what this does is it creates an entry in the MSDB.dbo.sysdac_instances_internal database with a version number, this version number can be changed in the project as well.  This is done by going to your projects properties and selecting “Project Settings” and the clicking the “Properties” button under “Output types.” This will open up a window that has a version number in it.

 

In my next post I will go over actually creating and deploying a project.

From the blog joshjoubert » CS@Worcester by Josh and used with permission of the author. All other rights reserved by the author.

Who am I…

Hello readers,

My name is Joshua Joubert and this is my first blog post.   Now, let me give a peak into my background and my reason for starting this blog. 

My background, well I’m currently a SharePoint developer for Raytheon.  Although, up to this point in my career with Raytheon. I have done very little in the way of SharePoint development, by this I mean the actual creation of SharePoint applications. This  doesn’t mean that I haven’t learned a great deal about SharePoint and how it works…we’ll get more in-depth into my experiences with SharePoint in future posts.  I have also touched upon PowerShell programming as well as MSBuild and more, a great deal more…details to come in later posts.

 The main reason that I opened this blog is to fulfill a requirement for my Independent Study in Computer Science.   Although, the main reason for this is for a course requirement, I think I will keep it and use it as a way to get helpful, hopefully helpful, information to my fellow developers.   

I feel this will be a good way for me to get information that I have come across and/or used to remedy issues that have arose during the development of projects that I have worked on and hopefully it will become a fount of knowledge for developers. A place for developers to come and find solutions or workarounds or even a new or better way to solve a problem that has arose for them.

From the blog joshjoubert » CS@Worcester by Josh and used with permission of the author. All other rights reserved by the author.

Who am I…

Hello readers,

My name is Joshua Joubert and this is my first blog post.   Now, let me give a peak into my background and my reason for starting this blog. 

My background, well I’m currently a SharePoint developer for Raytheon.  Although, up to this point in my career with Raytheon. I have done very little in the way of SharePoint development, by this I mean the actual creation of SharePoint applications. This  doesn’t mean that I haven’t learned a great deal about SharePoint and how it works…we’ll get more in-depth into my experiences with SharePoint in future posts.  I have also touched upon PowerShell programming as well as MSBuild and more, a great deal more…details to come in later posts.

 The main reason that I opened this blog is to fulfill a requirement for my Independent Study in Computer Science.   Although, the main reason for this is for a course requirement, I think I will keep it and use it as a way to get helpful, hopefully helpful, information to my fellow developers.   

I feel this will be a good way for me to get information that I have come across and/or used to remedy issues that have arose during the development of projects that I have worked on and hopefully it will become a fount of knowledge for developers. A place for developers to come and find solutions or workarounds or even a new or better way to solve a problem that has arose for them.

From the blog joshjoubert » CS@Worcester by Josh and used with permission of the author. All other rights reserved by the author.