locked
Using Older ASP.NET Tutorial Applications w/Visual Studio 2017 (database issue) RRS feed

  • Question

  • User-1308471560 posted

    When trying to open an older ASP.NET application in Visual Studio 2017 (community) because I'm back into ASP.NET developement after years of doing other technologies, I can't open the projects. Microsoft has closed down the old site that had these things but the code and all is available on GitHub, so that's where I got it (the link at https://docs.microsoft.com/en-us/aspnet/web-forms/overview/getting-started/getting-started-with-aspnet-45-web-forms/introduction-and-overview is long broken in that regard). I just hope that code is correct.

    The issue here is opening the local database, mdf, files. I get this error message in a popup:

    The Data Souirce value in the connection string specifies an instance of SQL Server that is not installed. To resolve this issue, you can either choose to instfgall the matching isntance of SQL Server or modify the Data Source value in the connection string.

    I'm trying to open the WingTip Toys application. The Server Explorer will not connect to the local database files, (*.mdf).

    The app.config has this:

    <entityFramework>
      <defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
        <parameters>
          <parameter value="v11.0" />
        </parameters>
      </defaultConnectionFactory>
      <providers>
        <provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
      </providers>
    </entityFramework>

    The Server Explorer has this for Default Connection string and Provider:

    Data Source=(LocalDb)\v11.0;AttachDbFilename="D:\Projects\ASP.NET\Wingtip Toys\WingtipToys\WingtipToys\App_Data\aspnet-WingtipToys-20131223105750.mdf";Initial Catalog=aspnet-WingtipToys-20131223105750;Integrated Security=True

    .NET Framework Data Provider for SQL Server

    WIngtipToys specific Connection String:

    Data Source=(LocalDB)\v11.0;AttachDbFilename="D:\Projects\ASP.NET\Wingtip Toys\WingtipToys\WingtipToys\App_Data\wingtiptoys.mdf";Integrated Security=True

    I did a fairly complete 2017 install, for web (including core, node etc.) - just not mobile or advanced C++. The database stuff should all be included. I did the developer edition of SQL Server 2017 as well because I wanted the more comprehensive SQL Server Management Studio and am familiar with it. This isn't migrating the database like a back end server import/restore, it's just using the mdf file in VS 2017.

    Things like double clicking the files (which merely goes to the Server Explorer) do nothing useful. l I'm not about to try to return to anything from the 2013 time frame. Those days were awful by today's standards, certainly the free versions from that era were horrible except that at a minimal level they worked. Just because I get a professional, if not Enterprise version at work doesn't mean I will pay for it at home, how much more so an older version. The community edition for learning- or in this case re-learning -makes a lot of sense and I like what Microsoft did. What I don't care for is the compatibility of the older local databases. The Microsoft way is to make it easy to do these tedious things - but in this case there is no obvious option provided. SS Mgt Studio does not work whatsoever with local database files.

    Does anyone have any suggestions? I was hoping this would be simple.

    Update 18-Jan-2020

    I found a good answer to a related issue - turning on role manager so I'd at least continue with the existing code (except a change to the web.config) to the admin/login/register page: https://stackoverflow.com/questions/3874279/the-role-manager-feature-has-not-been-enabled did that and it worked. Not exactly obvious, but it is simple. So anyone reading this, I am using VS 2019 and can launch the app. I only wish it had run out of the box ... but this will do.

    Thursday, January 2, 2020 1:55 AM

All replies

  • User409696431 posted

    v11.0 means SQL Server 2012 localDb.  (For SQL Server 2014 and later LocalDb use "mssqllocaldb" )

    Open a command prompt and type "sqllocaldb info".  You'll get a list of localdb instances.  To see the details of each, type "sqllocaldb info instance_name". 

    What results do you get?

    Thursday, January 2, 2020 3:20 AM
  • User288213138 posted

    Hi wesinsaratoga,

    wesinsaratoga

    The Data Souirce value in the connection string specifies an instance of SQL Server that is not installed. To resolve this issue, you can either choose to instfgall the matching isntance of SQL Server or modify the Data Source value in the connection string.

    Regarding this issue, you can try the following steps:

    1.In Visual Studio, go to Tools => Options => Database Tools => Database Connections. you will see the wrong LocalDb is used as datasource. as below screenshot.

    2.Change the database which is installed. Click on Ok and you are done. Now try creating the mdf file using Visual Studio and it should work.

    About how to get the names of the installed LocalDB you can refer to this link:https://www.codeproject.com/Tips/1042100/How-to-Resolve-The-Data-Source-value-in-the-connec

    Best regards,

    Sam

    Thursday, January 2, 2020 6:03 AM
  • User-1308471560 posted

    Right now it connects by changing the connection strings in web.config to

    <!-- OLD
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\aspnet-WingtipToys-20131223105750.mdf;Initial Catalog=aspnet-WingtipToys-20131223105750;Integrated Security=True" providerName="System.Data.SqlClient" />
    <add name="WingtipToys" connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\wingtiptoys.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
    -->
    <add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-WingtipToys-201312231057501;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-WingtipToys-20131223105750.mdf" providerName="System.Data.SqlClient" />
    <add name="WingtipToys" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;Initial Catalog=aspnet-wingtiptoysx;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\wingtiptoys.mdf" providerName="System.Data.SqlClient" />

    The new problem (this is the first time it's been run) I get an error as soon as it hits RoleActions.createAdmin(), with the exception being:

    System.Data.SqlClient.SqlException: 'Cannot create file 'D:\Projects\ASP.NET\Wingtip Toys\WingtipToys\WingtipToys\App_Data\aspnet-WingtipToys-20131223105750.mdf' because it already exists. Change the file path or the file name, and retry the operation.
    CREATE DATABASE failed. Some file names listed could not be created. Check related errors.'

    Well, the database was included with the github project and the only change was the connection string.

    I'm not really good with these sample app security scenarios, being used to high security environments with PKI and much more. We don't do this, can't so I'm not all that prepared to think it through, what it looks for, creates on the fly and such.

    So, should the file in the project not be there, or should there be a different reaction in RoleActions class? Obviously this is pretty early in the application pipeline, and "External Code" is on either side so I can't view that.

    Sunday, January 12, 2020 10:13 PM
  • User-1308471560 posted

    Hi Sam, I kind of tried that, and after posting but before your answer, another search (ah the world of search engines) dealing with other aspects of SQL Express and EF showed this:

    https://docs.microsoft.com/en-us/visualstudio/data-tools/upgrade-dot-mdf-files?view=vs-2019

    The problem is that let me load the project but wouldn't persist. My reply to Kathy gets it to connect - I simply looked for the syntax in VS 2017/2019 and came up with what I posted in my other reply. My Tools / Options data also does have, per your suggestion, (LocalDB)\MSSQLLocalDB.

    I've been using EF at work, or Java EE Beans or other technologies, and haven't seen Express in years (there was some SharePoint 2010/2013 Sandbox solutions which don't have "database" data, just lists and workflows in ASP.NET - like environment). I don't think I've seen Express since shortly after it came out, so it's as good as new. All normal work is big back ends (or Hadoop/Accumulo size data) - and generally I'd use SQL Server Developer edition on Win 10 Pro for projects I'd start from scratch. I still like creating data tier objects from scratch, so this latest error, I kind of know what it is, but I have not used this kind of role mgt in many years. As I told Kathy, I'm used to very locked down PKI and more. Far more strict and vastly different than is appropriate for a sample app - but the complex authentication and authorization has been "no second thought" for years so it's the simple approach that throws me.

    Exception thrown: 'System.Data.SqlClient.SqlException' in mscorlib.dll
    An exception of type 'System.Data.SqlClient.SqlException' occurred in mscorlib.dll but was not handled in user code
    Cannot create file 'D:\Projects\ASP.NET\Wingtip Toys\WingtipToys\WingtipToys\App_Data\aspnet-WingtipToys-20131223105750.mdf' because it already exists. Change the file path or the file name, and retry the operation.
    CREATE DATABASE failed. Some file names listed could not be created. Check related errors.

    I'm not clear on why it wants to create something that was part of the GitHub project. That's probably the first mystery for me. Thanks for the help. Oddly this might be more intuitive to newcomers who don't have my "baggage" so to speak.

    Sunday, January 12, 2020 10:25 PM
  • User409696431 posted

    Look at the line that throws the error.  What is the code doing?

    Monday, January 13, 2020 12:47 AM