• Microsoft

    Visual Studio 2012

    Where do I begin when your aging development environment starts to…. well… eat itself. 

    To be completely transparent, I’m not a big fan of using old dev environments to try to get production ready code up and running. Normally it’s not an issue, really. But, when one has folks mucking about with the domain and changing things that affect one’s working environment, there’s where the trouble starts.

    My VS 2012 environment started to act up last week, and at some point I simply had to terminate VS. Ya, not the best way to go about matters, but what can one do? The trouble started not in killing the VS process, rather trying to get it to run again. As I started up a new VS 2012 in Admin mode and “BlamO” a non-responsive process. The damn thing just would not start up. CRAP! After switching into “SafeMode”, I find that my old domain profile file locations had been removed from the Domain (you know that “Documents” folder location “App Data” where hidden things related to VS lives?) Wonderful, now what?! 

    One might ask, well why not move on to VS 2015 or better yet VS 2017 (I really like 2017!). Well one has to understand our production level systems. In a word, or two – they are OLD! I have to use VS 2012 to create SSIS projects for our SQL 2012 servers. While one can certainly develop SSIS packages for SQL 2012 using VS 2015, one cannot create the Initial package using anything but VS 2012 (yeap, one of perpetual jokes about how some teams at MS don’t cross pollinate should be inserted at this point- I’m think the SQL team and the VS team should talk more).

    Anyway, believing that there is solution- an odd fact about Moi- one finds these parameters for VS 2012 

    • /ResetUserData – (AFAICT) Removes all user settings and makes you set them again. This will get you the initial prompt for settings again, clear your recent project history, etc.
    • /ResetSettings – Restores the IDE’s default settings, optionally resets to the specified VSSettings file.
    • /ResetSkipPkgs – Clears all SkipLoading tags added to VSPackages.
    • /ResetAddin – Removes commands and command UI associated with the specified Add-in

    The important one here is /ResetUserData  – Since I already know something is screwed up with my domain profile (as revealed via safemode), this is where we start. Upon executing DEVENV.exe /ResetUserData VS starts and gives me all kinds to popups about component this missing and error loading that- and I’m thinking ‘oh joy this thing is really mucked now’.

    Patience….. after the dust settles… VS 2012 pops up into life, granted it’s missing some things on the start screen…. but it’s running! I quickly go into some settings to make sure I don’t run into some domain related problems.  And now I’m back at the OLD 2012 dev environment. 

    Did I mention that I’m not really a big fan of using Old dev environments?  🙄 

    The last part on this fixing my broken VS 2012 was to do a repair- turns out there was also some corruption of some the basic VS components… which is odd based on the fact that VS 2012 was still functional mostly. I suspect there where some installed extensions that may have been at the root of the problems. This part only took about an hour.

    ~ScottGeek

  • .Net Core,  Microsoft

    .net Core 2.1 and SQL via EF Core 2.1 -The revisit

    It’s time to revisit this topic but for the latest up dates for .Net Core (v 2.1.1) and EF Core (v 2.1)

    Let’s start with the common project using, in my case, VS 2017 15.7.4.  Start a .Net Project based on v 2.1.x (I currently have installed .Net Core SDK v 2.1.301
      (Gee think we have enough versions of things  😯 )

    I’m doing a .Net Core Class so I can get my DBContext and Table models in place….
    We start with some Packages:

    Microsoft.EntityFrameworkCore.SqlServer (2.1.1)
    Microsoft.EntityFrameworkCore.SqlServer.Design (1.1.5)
    Microsoft.EntityFrameworkCore.Tools (2.1.1)

    Next, time for a database and let’s Scaffold a DB Context and our models… On the .Net Core project start up the Package Manager Console.

    dotnet ef dbcontext scaffold 
      "Server={ServerName};DataBase={DataBaseName};Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
       Microsoft.EntityFrameworkCore.SqlServer
       --output-dir Models
       --table {table1Name} --table {table1Name} --table {table1Name} .....
    For Connection Strings to SQL with a user/pass, an example would be
    "Server={ServerName;DataBase={DataBaseName}g;Integrated Security=False; User ID={sql user};Password={sql user Pass};
    Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;
    ApplicationIntent=ReadWrite;MultiSubnetFailover=False"

     

    The Walk-Through…

    Line 1 – dotnet ef dbcontext scaffold This is the start of the command. As we see dotnet is the actual start of the SDK utility. It is worth looking this up. “ef dbcontext scaffold” is how we start  the EF scaffold.
    Line 2 – The Connection String **1
    “Server={ServerName};DataBase={DataBaseName};Integrated Security=True;Connect   Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False”
    Line 3 – This is the provider used for MS SQL server. Yes it would be different if another database was being used.
    Line 4 – The –output param is giving us a way to make sure we put all models/dbcontext in a folder in the project.
    Line 5 – The –table allows one to generate models (and DbContext) for only certain tables in the DB.
     

    **1    This is the standard SQL connection string. This will take on various forms depending on what you are connecting to. And yes, one can use the localdb.

     

     

     

     

     

  • .Net Core,  Microsoft

    .net Core 2.0 and SQL via EF Core 2.0

    So I can never remember the order that these goes in so Here we go:

     A console App with .net Core/SQL Server/EF Core 2.0

    – In VS 2017 – Create a in .Net Core a Console App (.NET CORE)
    -Package Manager Console: 

    Install-Package Microsoft.EntityFrameworkCore.SqlServer  [Current Version was 2.0.1]
    Install-Package Microsoft.EntityFrameworkCore.Tools  [Current Version was 2.0.1]
    Install-Package Microsoft.EntityFrameworkCore.SqlServer.Design  [Not sure this one is required]

    Now let’s say we have a database and table…. Let’s reverse engineer it!

    Scaffold-DbContext “<that magic connect string>” Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models
      This is command that will use the <that magic connect string> and the provider Microsoft.EntityFrameworkCore.SqlServer with the code generation going into the Models sub-directory. 

    Examples <that magic connect string>

    For local DB and table: “Server=(localdb)\mssqllocaldb;Database=Blogging;Trusted_Connection=True;” 

    For a real SQL Server connection instance: 

     Scaffold-DbContext "Server=Orion;DataBase=Blogging;Integrated Security=False;
    User ID=sa;Password=****;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;
    ApplicationIntent=ReadWrite;MultiSubnetFailover=False"
    Microsoft.EntityFrameworkCore.SqlServer -OutputDir Models

    Also add the table parameter to get only certain tables   -table Blogs, Post
     

    So that was the Hard part… now some sample code:

    Make sure you add using Microsoft.EntityFrameworkCore; And if you put the dbContext into it’s own folder, make sure you include the class namespace.

    
    using System;
    using Microsoft.EntityFrameworkCore;
    using conAppSqlCore.Models;
    
    namespace conAppSqlCore
    {
        class Program
        {
            static void Main(string[] args)
            {
                Console.WriteLine("Hello World!");
                using (var db = new BloggingContext())
                {
                    foreach (var blog in db.Blog)
                    {
                        Console.WriteLine($"Name URL - {blog.Url}");
                    }
                }
                Console.ReadLine();
            }
        }
    }