Deborah's Developer MindScape






         Tips and Techniques for Web and .NET developers.

Archive for VB.NET

February 7, 2014

Deploying a DACPAC with SqlPackage

There are several different tools that you, the DBA, or another individual can use to deploy a DACPAC as defined in this prior post. This current post details how to deploy a DACPAC using SqlPackage.

SqlPackage is a command line utility that automates DACPAC operations, including publishing a DACPAC to a target database. On my system, I found SqlPackage.exe in: C:\Program Files (x86)\Microsoft SQL Server\110\DAC\bin.

SqlPackage has many parameters, properties, and variables you can use to perform DACPAC operations. See this MSDN link for details.

The benefits of using SqlPackage are:

  • Its straight-forward and the API is clear.
  • You can include it in a batch file.
  • You can use it to automate your deployment process.

Here are the basic steps for deploying a DACPAC using SqlPackage from the command line:

  • Open a command prompt (cmd.exe).
  • Execute SqlPackage.exe with the desired parameters.

For example: to deploy a DACPAC using a publishing profile, the command would look like this:

“<Path>\SqlPackage.exe”
/Action:Publish
/SourceFile:“<Path>\ACM.Database.dacpac”
/Profile:”<Path>\ACM.Database.publish.xml"

Where <Path> is the appropriate path to your files.

Executing the command displays status messages as it performs the publish operation as shown in the screen shot below.

image

As another example: to deploy a DACPAC by specifying the target database information instead of using a publishing profile, the command would look like this:

“<Path>\SqlPackage.exe”
/Action:Publish
/SourceFile:“<Path>\ACM.Database.dacpac”
/TargetDatabaseName:TestACM
/TargetServerName:".\sqlExpress"

Where <Path> is the appropriate path to your files.

The result is shown below.

image

Use SqlPackage to deploy the DACPAC anytime you want to perform the deployment using the Command window or within a script.

Enjoy!

For more information on this and other SQL Server Data Tools (SSDT) features, see my latest Pluralsight course: "Visual Studio Data Tools for Developers", which you can find here.

Deploying a DACPAC with SQL Server Management Studio

There are several different tools that you, the DBA, or another individual can use to deploy a DACPAC as defined in this prior post. This current post details how to deploy a DACPAC using SQL Server Management Studio.

Many DBA’s are more comfortable using SQL Server Management Studio. So if the developers provide a DBA with a DACPAC, the DBA may prefer to use SQL Server Management Studio to deploy it.

This post covers the steps for using SQL Server Management Studio 2012 to deploy a DACPAC. For SQL Server Management Studio 2008 R2, the steps are different and it only supports older versions of DACPACs. However, you CAN use SQL Server Management Studio 2012 to connect to an older SQL Server instance, such as SQL Server 2005 or 2008 R2, and deploy a DACPAC.

Here are the steps for deploying a DACPAC with SQL Server Management Studio 2012:

  • Open SQL Server Management Studio.
  • Connect to the SQL Server Instance containing the database to deploy to.
    • Notice that in the example below, I am connecting to a SQL Server 2008 R2 SQL Express instance.
  • Navigate the tree in the Object Explorer to the database to deploy to.
  • Right-click on the database name and select Tasks | Upgrade Data-tier Application…

image

  • The Upgrade Data-tier Application wizard is displayed. It presents the set of steps that will be executed by the wizard.

image

  • Click Next.

image

  • Use the Browse button to find and select the DACPAC file. It is located in the Bin\Debug directory of the database project on the developer’s machine. Or where ever it was put if the file was provided to a DBA or other individual.
    • The default expected location is: C:\Users\<userName>\ Documents\SQL Server Management Studio\DAC Packages
  • Click Next.

image

  • The information in the DACPAC is compared with the target database.
    • If the target database was changed externally from a DACPAC deployment (by making changes directly to the database), you are warned that the database was changed.
    • You can optional proceed anyway, or exit the wizard and research the issue.
  • Click Next.

image

  • The deployment script is automatically generated.
  • From the above dialog, you can optionally select to save the deployment script to a file.
  • When ready, click Next.

image

  • The Upgrade Plan is then displayed for review.
    • You can elect to save the report.
    • You again have the option to save the generated script.
  • Click Next.

image

  • A summary is displayed containing the information that will be used during the deployment.
    • Note that in the above screen shot, I opened each node in the summary so you can see the details.
  • When you are happy with the summary information, click Next and the deployment process (finally!) begins.

image

  • The generated script is executed, completing the DACPAC deployment process.
  • If desired, click Save Report.
  • Then click Finish.

If you compare this process to the steps for deployment using Visual Studio, you can see that there are MANY more steps. But the DBA may be happy with all of these extra steps because they provide additional verification before deploying the DACPAC.

Enjoy!

For more information on this and other SQL Server Data Tools (SSDT) features, see my latest Pluralsight course: "Visual Studio Data Tools for Developers", which you can find here.

February 5, 2014

Deploying a DACPAC with Visual Studio

There are several different tools that you, the DBA, or another individual can use to deploy a DACPAC as defined in this prior post. This current post details how to deploy a DACPAC using Visual Studio.

Starting with Visual Studio 2013, the SQL Server data tools (SSDT) are available in*every* edition of Visual Studio, including the Express editions. So the DBA or other deployment personnel can use one of the free Express editions of Visual Studio to manage database projects and deploy DACPACs.

If you have Visual Studio 2012 or older, see this blog post for information on obtaining the appropriate SSDT.

Here are the steps for deploying a DACPAC with Visual Studio:

  • Open the SQL Server Object Explorer window (View | SQL Server Object Explorer).
  • Navigate to the database you wish to deploy to. This is the database that will be updated. In this case it is TestACM to deploy the DACPAC to the test database.
  • Right-click on the database and select Publish Data-tier Application… from the context menu.

image

  • The Publish Data-tier Application dialog is displayed (see below).
  • Use the Browse button to find and select the DACPAC file. It is located in the Bin\Debug directory of the database project.

image

  • When you are finished specifying the publish parameters, click the Publish button to publish the DACPAC to the target database.

The status of the deployment appears in the Data Tools Operations window.

image

Use the SQL Server Object Explorer within Visual Studio to deploy a DACPAC to any database.

Enjoy!

For more information on this and other SQL Server Data Tools (SSDT) features, see my latest Pluralsight course: "Visual Studio Data Tools for Developers", which you can find here.

Deploying a DACPAC

If you are using Visual Studio 2012 or above, you can create a SQL Server Database Project to include all of your table, view, stored procedure, and data scripts. (See #1 below)

When you build the Database Project (#2), Visual Studio generates a DACPAC file (#3). The DACPAC is a single unit of deployment that you, your DBA, or another individual can use to deploy database schema changes or reference data.

When deployed, the SQL Server Data Tools (SSDT) perform some magic. They compare (#4) the contents of the "master" database as defined in the DACPAC (#3) to the target deployment database.

SSDT then automatically generates (#5) a change script (#6). The change script includes all of the changes to apply to the target database to bring its schema up to match the schema defined in the DACPAC and to deploy any reference data defined in the DACPAC.

The SSDT then executes (#7) the script against the target database and the deployment is complete.

COOL!

image

So I created my database project, built it to generate the DACPAC. Now what? How do I make it do all of that magic? How do I (or my DBA) actually deploy the DACPAC?

There are many different ways to deploy a DACPAC:

Click a link above to view details on deploying a DACPAC with each of these techniques.

Enjoy!

For more information on this and other SSDT features, see my latest Pluralsight course: "Visual Studio Data Tools for Developers", which you can find here.

February 2, 2014

20 Years of Speaking: VBITS/VSLive!

Filed under: C#,VB.NET,Visual Studio @ 7:44 pm

It was 1994. I got up enough courage to present a session at the second annual VBITS conference in San Francisco. My talk was on using object-oriented techniques in VB3. Yep, you read that right … VB 3!

I have the mug to show for it!

IMG_2656

The talk was not hugely popular (who would want to attempt object-oriented style coding in VB3?) … but luckily the Microsofties in the back of the room knew what was coming … that the soon to be released VB 4 would revolutionize VB by providing some object-oriented features. What timing!

From that time on I have presented sessions at VBITS and then VSLive! every year. Some talks in far away places like Sydney and London. Others all over the US such as Orlando, New York, Las Vegas, and Seattle.

IMG_2639

Regardless of the location, the attendees are always great! And as an attendee myself, I always learn something new.

It’s fun to think back at the past 20 years! VB 3 on through VB 6, then to VB.NET and C#. The conferences are such a good way to keep up with the fast changing software development field we all work in.

Shall we go for 20 more?

January 27, 2014

Join me at Live! 360 in Las Vegas!

Filed under: C#,VB.NET,Visual Studio @ 12:46 pm

I’ll be speaking at Live! 360 DEV, March 10-14 in Las Vegas, NV Click to Register. 

LSPK24

Live! 360 DEV provides you with immediately usable training and education that will keep you relevant in the workforce.

I’ll be presenting the following sessions:

Visual Studio 2013 New IDE Features Part I
Visual Studio 2013 New IDE Features Part II

SPECIAL OFFER: As a speaker, I can extend $500 savings on the 5-day package. Register here: http://bit.ly/LSPK24

Amplify your knowledge at Live! 360 DEV Las Vegas — bring the issues that keep you up at night and prepare to leave this event with the answers, guidance and training you need.  Register now: http://bit.ly/LSPK24Reg

Enjoy!

November 4, 2013

XAML Intellisense

Filed under: C#,VB.NET,Visual Studio,XAML @ 9:52 am

In Visual Studio 2013, there were quite a few changes/enhancements to XAML Intellisense. Prior posts covered the most noticed new features … this post covers some of the other changes to Intellisense for XAML.

Prior posts on XAML Intellisense:

This post covers:

  • Fuzzy Matching
  • Camel Case Matching
  • Substring Matching

Fuzzy Matching

Fuzzy matching finds XAML element and attribute names, even if you mistype them.

In the screen shot below, typing "Stakpa" picked up StackPanel.

image

I tried several other common typing mistakes and was unable to get this to work consistently. It seems that it needs the first few characters to be correct.

In the screen shot below I just missed the "t" and got this:

image

Camel Case Matching

Camel case matching allows you to type the first letter of each "word" in a name to find it in Intellisense.

Though this is called camel case matching, it also uses Pascal case matching since the majority of the elements and attributes are Pascal cased.

In the screen shot below, I typed "SP":

image

Substring Matching

Substring matching finds names using a substring search.

In the screen shot below, I typed "Box":

image

This finds the first occurrence of Box anywhere in the string.

But this is a find and not a filter. So it does not filter the list to all elements containing "box". It just advances to the first match. And there is no way to get to the next match.

Use these features as you work with XAML to more quickly select the element or attribute you want from Intellisense.

Enjoy!

For more information on the many new Visual Studio 2013 features, check out my new Pluralsight course: Mastering Visual Studio 2013.

November 1, 2013

XAML: Intellisense for Bindings And the Data Context

Filed under: C#,VB.NET,Visual Studio,XAML @ 3:39 pm

The new Intellisense for Binding expressions in Visual Studio 2013 (introduced in this prior post) provides a quick and effective way to add property bindings to your XAML. But it doesn’t "just work". You have to set the Data Context to enable Intellisense.

To get Intellisense to work with Binding expressions, you need to provide Intellisense with a design-time instance of the class containing the properties for the binding. This is done through the Data Context.

If your XAML-based application uses the Model, View, View-Model (or MVVM) pattern, the Data Context is set to an instance of the View-Model.

There are several options for where and how you set the Data Context to an instance of the View-Model, depending on the framework you are using (if any) and your approach.

One option is to set the Data Context directly in the page as shown below:

image

In this example, the Data Context is set to the View-Model directly in the XAML. The vms prefix in the code above is the abbreviation set for the View-Model namespace.

By setting the Data Context for the page directly in the XAML, an instance of the View-Model is constructed when the page is displayed in the designer. So the Intellisense has an instance of the class at design time that it can use to determine the bindable properties. You also get the added benefit of design-time data, as shown below.

image

Alternatively, you could set the Data Context in the code behind or use a factory pattern. But if you use any technique other than setting the Data Context within the XAML, Intellisense won’t have a design-time Data Context and therefore won’t display the list of bindable properties.

If you don’t have the Data Context defined within the XAML, but still want the benefits of Intellisense and design-time data, you can set up a design-time only Data Context instance. This is shown in the example below.

image

The d: prefix is for design-time only features. You may have used it to define the DesignHeight and DesignWidth of a page as shown in the Page markup tag above.

Assigning a value to the d:DataContext sets the design-time Data Context and enables basic Intellisense for Binding expressions.

In this example, the design-time Data Context is set to d:DesignInstance with a Type set to vms:CustomerListViewModel. This is the same View-Model used in the first example above.

The IsDesignTimeCreatable=true attribute ensures that an instance of the type is created at design time. By adding this attribute, the Intellisense will display all of the bindable properties. In addition, you get design-time data.

Use one of these techniques to take advantage of Intellisense for Binding expressions (and design-time data).

Enjoy!

For more information on the many new Visual Studio 2013 features, including a step by step walk through of the design-time Data Context, check out my new Pluralsight course: Mastering Visual Studio 2013.

XAML: Intellisense for Bindings

Filed under: C#,VB.NET,Visual Studio,XAML @ 10:01 am

Visual Studio 2013 provides Intellisense for your Binding expressions!

One of the great things about XAML is its binding capabilities. But how much time have you wasted trying to find the correct name and spelling of properties for your bindings?

Not any more!

The Binding mark-up extension now supports Intellisense!

  • Move the cursor into the Binding markup extension anywhere after the Binding keyword.
  • Press Ctrl + Space

image

Yes!

  • Arrow down to the desired property.
  • Press Enter or Tab to select it.

Notice that the drop down list contains all of the attributes for the binding (such as FallbackValue and Mode)  in addition to the properties of the current data context. That makes the list rather long.

image

Luckily the properties of the current data context are identified in the list with a different icon. So you can readily see which of the Intellisense list items are your bindable properties and which are attributes of the binding markup extension.

Enjoy!

For more information on the many new Visual Studio 2013 features, check out my new Pluralsight course: Mastering Visual Studio 2013.

October 31, 2013

XAML: Intellisense for Resources

Filed under: C#,VB.NET,Visual Studio,XAML @ 10:30 am

Visual Studio 2013 now provides Intellisense for your XAML resources.

If you code your XAML directly using the Code Editor you’ve seen the XAML Intellisense. Sure, it helps by giving you the list of element tags and the valid attributes of the type.  But in prior versions of Visual Studio, Intellisense was lacking in a few key areas. For example, it did not help you find your resources.

One of the really great things about XAML-based applications is the flexibility and control in defining styles for the displayed elements. But as we add more styles, it gets harder and harder to keep track of all of the style resources.

Even in a small application it’s hard to remember which styles have been defined. The user wants the column headers to be left-justified. Did we already create a style for that?

In prior versions of Visual Studio, we would have to start searching through our style resources to see if we have a left-justified header style.

Not any more!

The Static Resource mark-up extension now provides Intellisense!

  • Move the cursor into the Static Resource extension anywhere after the StaticResource keyword.
  • Press Ctrl + Space

image

Sweet!

  • Arrow down to the desired style.
  • Press Enter or Tab to select it.

And the Intellisense is smart! The drop down list only contains styles appropriate for a TextBlock element.

image

Using Intellisense on a Border element displays this:

image

The drop down list does not include any of the TextBlock styles, only the styles defined for a Border element.

Intellisense also understands scope. It will combine resources appropriate for the current scope including resources defined in the page and resources defined in resource dictionaries.

The Intellisense available with the StaticResource mark-up extension helps you locate and select the styles you need when you need them.

And it works for more than styles. If you have any other resources defined in your application, such as references to your converters, those also support Intellisense.

Enjoy!

For more information on the many new Visual Studio 2013 features, check out my new Pluralsight course: Mastering Visual Studio 2013.

« Previous PageNext Page »

© 2019 Deborah's Developer MindScape   Provided by WPMU DEV -The WordPress Experts   Hosted by Microsoft MVPs