SQL Server Object Explorer not showing a database - c#

It's a very small code-first EF6 Project. I added a migration and updated a database successfully. Here's the output:
PM> update-database -Verbose
Using StartUp project 'ChattyServer'.
Using NuGet project 'ChattyDataModel'.
Target database is: 'ChattyDataModel.ChattyContext' (DataSource: .\SQLEXPRESS, Provider: System.Data.SqlClient, Origin: Convention).
No pending explicit migrations.
Running Seed method.
However, when I open the SQL Server Object Explorer, I can't find my database:
UPD: The app.config - which connection string should I use for LocalDb?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<section name="entityFramework"
type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 --></configSections>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
UPD: Updated the app.config, added:
<connectionStrings>
<add name="DbConnect"
connectionString="Data Source=(localdb)\ProjectsV13;Initial Catalog=master;Integrated Security=True;ConnectTimeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False" />
</connectionStrings>
Then created a new migration and updated a database. No changes in the SQL Server Object Explorer
UPD I changed the directory from master to chatty, created a new migration and updated the db-still can't see db in the SQL Server Object Explorer

Firstly: You are using the Master database. Check this post to know how to set your connection string: Cant find my EF code first database.
Secondly: You didn't connect to SQLEXPRESS:
In your Server Explorer click on Connect to Database.
Then in the Server name type .\sqlexpress
Then Test Connection.
then in the Select or enter a database name you should get your
database.

I had the same problem and found that I hadn't connected SSOX to the right instance of SQL Server. I had my older full version connected, not the SQL Express. The program was functioning perfectly but not on the db I was looking at!
I connected to (my pc)\SQLExpress and voila! I could see my database! slaps forehead
Hope that helps someone else with the same problem.

Related

Cannot connect asp.net web forms to local mySQL db

I have wasted nearly a month trying to resolve this issue and have had no luck. I think I have tried everything I can find in the forums.
So at the moment all I want to be able to do is have my asp.net web forms connect to my local database and to be able to use the asp.net Identity.
I am using Visual Studio Community 2017 (Version 15.9.3) and have downloaded the latest MySQL Workbench 8.0 (Version 8.0.13) also downloaded the latest MySql.Data.dll (Version 8.0.11.0).
So that I can be sure that it is not something I have done else where in my project I have created a new asp.net web app (.net framework). I have selected web forms and changed the Authentication to Individual User Accounts.
In web config I have changed the following:
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="DefaultConnection" connectionString="server=localhost;User Id=root;password=****;database=testdb" providerName="MySql.Data.MySqlClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework" />
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
</providers>
</entityFramework>
Within mysql workbench I have created a new Schema called testdb.
When I run the project I get this error
System.InvalidOperationException: 'The Entity Framework provider type 'MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=6.8.3.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' registered in the application config file for the ADO.NET provider with invariant name 'MySql.Data.MySqlClient' could not be loaded. Make sure that the assembly-qualified name is used and that the assembly is available to the running application. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.'
I have followed the link the error gives me but I am not sure exactly what it is telling me, I know some people will tell me it is given me the answer but I have spent so much time reading it I have no idea what it is telling me now. I am not asking for people to give me the but I really do need some help.
Edit:
Thank you Bradley and SH7 that got the web site started with out an error, now I am not sure if I need to start a new question here, but when I click on Register and enter my email and password it gives me this error.
System.Data.Entity.Core.EntityCommandExecutionException: 'An error occurred while executing the command definition. See the inner exception for details.'
MySqlException: Table 'testdb.aspnetusers' doesn't exist
Yes I know that means that the table does not exists, but I was under the impression that when you first register a user it would create all the tables needed for Identity.. While I am waiting for help I will add a new table and see if I can connect to that.

Entity Framework provider error

Hello guys I am strugling with connecting to sql database server. I am using Entity framework v6 and trying code first approach for the first time. Below I will show you my app.config file and error message I get I checked out similar questions and most of answers were about missing EntityFramework.SqlServer.dll I have this dll referenced
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.2" />
</startup>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
<connectionStrings>
<add name="HotelDB"
connectionString="Data Source=(localdb)\v11.0;Initial Catalog=master;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=True;ApplicationIntent=ReadWrite;MultiSubnetFailover=False"/>
</connectionStrings>
</configuration>
Error Message:
System.InvalidOperationException: No Entity Framework provider found for the ADO.NET provider with invariant name 'System.Data.SqlClient'. Make sure the provider is registered in the 'entityFramework' section of the application config file. See http://go.microsoft.com/fwlink/?LinkId=260882 for more information.
Have you found a solution for this problem? Otherwise you could take a look here: Entity Framework Provider type could not be loaded?
Most of the time when I see this exception it's because the web application doesn't have Entity Framework installed (and / or missing the EntityFramework.SqlServer.dll).
So to give an example, if you have 2 projects in a solution:
WebApp
DataAccess
and with Entity Framework installed in the DataAccess project. When wanting to call a method on a class (for example a repository) from the DataAccess project within the WebApp, 2 things are needed:
WebApp needs a reference to DataAccess
Webapp also needs EF to be installed
When DataAccess has EF installed and then added as a reference to WebApp, the WebApp project will (normally) also install EF. Sometimes in unexpected situations the installation of EF in the WebApp fails. Therefore not adding the needed references and showing the exception message you mentioned. Hopefully this answer will help some others.
I also had a similar problem
My problem was solved by doing the following:
If nothing of the solutions worked then check both the packages.config of WebApp and DataAccess for the version of Entity Framework. In case you see or don't see the entry of EF in the packages.config file of WebApp, go to the reference and delete the EF from WebApp and install it again using the package manager console giving the following command:
Install-Package "EntityFramework" -Version (Version number)
where Version number is the version that's present in the packages.config of DataAccess.
Example:
Install-Package "EntityFramework" -Version "6.1.3"

Getting an error from Entity Framework(type initializer exception)

I' am getting this:
The type initializer for 'System.Data.Entity.Internal.AppConfig' threw an exception.
error in my Entity Framework.
I read this Question and the possible answers, however non of them worked for me. Here is my App.config file:
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="SalesReportEntities"
connectionString="metadata=res://*/SalesReportModel.csdl
|res://*/SalesReportModel.ssdl
|res://*/SalesReportModel.msl;
provider=System.Data.SqlClient;
provider connection string="data source=.;
initial catalog=Training;
integrated security=True;
MultipleActiveResultSets=True;
App=EntityFramework""
providerName="System.Data.EntityClient" />
</connectionStrings>
<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>
</configuration>
What other possible things can cause this error?
I can offer a few suggestions and some are similar to the thread you already looked at:
Can you use SQL Management Studio and verify this database exists and has tables and is currently in a responsive state?
Put your 'connectionStrings' section after the < providers > node.
Your parameter value is 'v11.0' which seems to be targeting a version of SQL Server 2012. Mine that I am looking at now is similar to yours but just states: "mssqllocaldb". Which I believe is just the default instance of sql server from the connection you specify.
Uninstall Entity Framework completely and get it again from NuGet. I assume you are using Visual Studio so in 2015 it is Tools>NuGet Package Manager>Manage NuGet Packages. Uninstall, check your app config and 'References' that 'EntityFramework' is gone. Reinstall and check your settings again.
Are you trying to reference a project that entity lives in in another project or is it self contained? If so you need to target EF just like you were on the source project with adding EF to that project and a config the same.
You may also want to post the entire exception for better answers too.

Code-first EF database not auto-generating on startup

I have a new ASP.NET web application I am calling "Smartifyer" that was empty to start with. I added EntityFramework with Nuget and have created a model called WordModel and the following context:
public class SmartifyerContext : DbContext
{
public SmartifyerContext()
: base("SmartifyerDatabase")
{
}
public DbSet<WordModel> Words { get; set; }
}
Within Web.config in the root directory I have the following configurations:
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<connectionStrings>
<add name="SmartifyerDatabase"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\SmartifyerDb.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
</connectionStrings>
<system.web>
<compilation debug="true" targetFramework="4.5" />
<httpRuntime targetFramework="4.5" />
</system.web>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="mssqllocaldb" />
</parameters>
</defaultConnectionFactory>
<providers>
<provider invariantName="System.Data.SqlClient" type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" />
</providers>
</entityFramework>
</configuration>
When running a test on the context, the Find method takes about 30 seconds until it times out with the following error:
System.Data.SqlClient.SqlException: A network-related or
instance-specific error occurred while establishing a connection to
SQL Server. The server was not found or was not accessible. Verify
that the instance name is correct and that SQL Server is configured to
allow remote connections. (provider: SQL Network Interfaces, error: 26
- Error Locating Server/Instance Specified)
I have a pretty poor understanding of setting up SQL connections and what all the configurations within Web.config do. I would like the .mdf database file to be auto-generated if it is not present but I am unsure how to modify my configurations to do that.
EDIT WITH SOLUTION:
All of my connection config and database stuff was setup correctly. My problem was that I was running a unit test which was using the test project's app.config file rather than the main project's web.config. Copy and pasting my web.config into the test project's app.config fixed the issue!
The error you're getting is because the EF is not able to locate the database instance service. The EF have default connection string that connects to developer database known as LocalDB\V11.0. Here your application is trying to connect to LocalDB\V11.0 as specified in ConnectionString.
<add name="SmartifyerDatabase" connectionString="Data Source=(LocalDB)\v11.0; ......
You must ensure that LocalDB instance is installed on you machine. see this answer. If it's not there install it and try to connect manually to the LocalDB instance then try with the application. Hope this will resolve your issue.
For information about the SQL LocalDB see this MSDN article.
You can also use your SqlExpress or other Sql database if it's installed on your machine. Just change the DataSource property in the connectionstring and you will be good to go.

Using the ADO.NET Entity Framework with the Advantage Database Server

I'm creating and WPF application using the MVVM in VS 2013; first implementation was with SQL server and it worked like a charm.
Second phase is to have support for Advantage Sybase. For this I have downloaded Advantage Data Provier to have the connection in connection drop down list ( http://www.codeguru.com/csharp/.net/article.php/c17027/Using-the-ADONET-Entity-Framework-with-the-Advantage-Database-Server.htm ).
For VS 2013 there is a problem with this and the workaround is to manually edit the registry to have this provider (http://blog.nwoolls.com/2012/07/25/registering-missing-data-providers-with-visual-studio-2012/).
Now I have the provider in the drop down, I can select the provider, but when I try to generate the script for data base generation I have a weird error:
ERROR:
"
Could not find the appropriate DbProviderManifest to generate the SSDL. The supplied provider Manifest token '2008' is not valid.
"
Any ideas on how to use the DB Provider correctly?
First, VS 2013 is not yet officially supported by Advantage Database Server. I believe official support may be available once ADS 12.0 is released.
But.... I did get a chance to try it out and it is working.
Be sure to that you are using the 11.1 ADS .Net dataprovider. It includes support for Entity Framework 5 (As far as In know, nothing from ADS includes support for EF6 at this time)
Export the 4 keys mentioned in your second article from Nate Wools. In my case I exported from VS 2012 (11.0 in the registry path). Full find/replace on 11.0 -> 12.0 including the assembly version for Microsoft.VisualStudio.Data.Framework
(Disclaimer, I've not had a chance to try MVVM, just a plain Windows Form app, but it worked well)
App.Config that was automatically created and updated. Maybe check against yours?
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<configSections>
<!-- For more information on Entity Framework configuration, visit http://go.microsoft.com/fwlink/?LinkID=237468 -->
<section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=5.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" />
</configSections>
<startup>
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.5.1" />
</startup>
<connectionStrings>
<add name="Entities" connectionString="metadata=res://*/Model1.csdl|res://*/Model1.ssdl|res://*/Model1.msl;provider=Advantage.Data.Provider;provider connection string="Data Source=E:\ADS\School\School.add;User ID=adssys"" providerName="System.Data.EntityClient" />
</connectionStrings>
<entityFramework>
<defaultConnectionFactory type="System.Data.Entity.Infrastructure.LocalDbConnectionFactory, EntityFramework">
<parameters>
<parameter value="v11.0" />
</parameters>
</defaultConnectionFactory>
</entityFramework>
</configuration>

Categories

Resources