ASP.NET / MVC4 Connection String to SQL Server 2008 error - sql-server-2008

I am working through an ASP.NET MVC4 tutorial from ASP.net. This is the second tutorial in which I am getting database connection errors. Here is the error:
An error occurred while getting provider information from the database. This can be caused by Entity >Framework using an incorrect connection string. Check the inner exceptions for details and ensure that >the connection string is correct.
Here are my connection strings. The first one was generated by the template, the 2nd was copied verbatim from the tutorial. I am running SQL Server 2008, not express. That may be my problem. The database is created automatically from the application as well. I do not have a login / password that I am aware of for this local db.
<add name="DefaultConnection"
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=aspnet-MvcMovie-20130830102032;Integrated Security=SSPI"
providerName="System.Data.SqlClient" />
<add name="MovieDBContext"
connectionString="Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Movies.mdf;Integrated Security=True"
providerName="System.Data.SqlClient"/>
I've looked on connectionstrings.com & asp.net to find a resolution and I am not clear on the fix. The error has to be in the connection string, but I am unsure which one, if not both, it is.
Thanks
I just changed the data source to Data Source=. and here is the error now:
There is already an object named 'PK_dbo.Movies' in the database.
Could not create constraint. See previous errors.
I tried to delete the database in sql server and was unable to when right clicking on it and pressing delete. Any ideas?

Related

NServiceBus .netcore + MySql

I’m trying to configure NServiceBus in a simple .netcore3.1 console application to use MySql.
I have the Persistence set to SqlPersistence with a SqlDialect.MySql and i'm using the SqlServerTransport*.
My connection string is of type MySqlConnection :
server=localhost;user=root;database=database;port=3306;password=password;AllowUserVariables=True;AutoEnlist=false
When I run the application, I get the error :
System.Exception: ‘Pre start-up check failed: Could not open connection to the SQL instance. Check the original error message for details. Original error message: Keyword not supported: **port**
Does anyone have any ideas what it might be? Any help would be great!
FYI. I have efcore up and running using and connecting to the MySql database.
So it turns out I was trying to use the SQL Server transport configured with MySql. This is not supported.
MySql can only be used in the persistence layer.
Particlular Support -
"The SQL Server Transport unfortunately only supports SQL Server.
Unfortunately you’ll have to select another technology to enable
messaging."
Where are you storing your connection string? Could the cause be that you did not specify the correct provider name providerName="MySql.Data.MySqlClient"?
<connectionStrings>
<add name="devConnectionString" connectionString="server=go.itelescope.net;port=3307;user id=xxxxxxxx;password=xxxxx;persistsecurityinfo=True;database=dev"
providerName="MySql.Data.MySqlClient" />
</connectionStrings>

AppHarbor: Connecting to a MySQL DB via ASP.NET MVC 5 + Dapper

I'm trying to get an application up and running on AppHarbor. It's been smooth sailing for the most part, but today I'm having trouble connecting to my MySQL database.
Using the credentials AppHarbor provided me with, I successfully connected to the mySQL database instance using dbForge Studio Express, created the necessary SQL schema, and populated the tables with data. Now I'm trying to use the following C# code to do a simple query using Dapper:
var sqlConnStringBuilder = new SqlConnectionStringBuilder(ConfigurationManager.ConnectionStrings["AppHarborMySql"].ConnectionString);
using (var db = new SqlConnection(sqlConnStringBuilder.ConnectionString))
{
db.Open();
// Do database query stuff
return result;
}
But this is the error that I'm running into, when I try to open the database connection:
An exception of type 'System.Data.SqlClient.SqlException' occurred in
System.Data.dll but was not handled in user code
Additional information: 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: Named Pipes Provider, error: 40 - Could not open a
connection to SQL Server)
This is how I've declared the connection string in Web.config:
<connectionStrings>
<add name="AppHarborMySql" connectionString="server=MYDOMAIN.mysql.sequelizer.com;database=MYDBNAME;uid=MYUSERNAME;pwd=MYPASSWORD" providerName="System.Data.SqlClient" />
</connectionStrings>
Am I missing something obvious? I'm using ASP.NET MVC 5.x and the latest version of Dapper... thanks in advance!
And of course, despite having spent the better part of an hour investigating, I discover the answer immediately after posting the question.
For anyone else who may run across the same problem: I added the MySql.Web NuGet package to my MVC project, added using MySql.Data.MySqlClient; to the top of my page, and then changed my code to point from SqlConnection to MySqlConnection. Here's what my working code block now looks like:
using (var db = new MySqlConnection(ConfigurationManager.ConnectionStrings["AppHarborMySql"].ConnectionString))
{
db.Open();
// Do database query stuff
return result;
}

Ef code first migrations on server:Cannot open database "blahblah" request by the login. The login failed

There are a million threads like this but none where the answers worked.I'm trying to get this database set up on my server (which I can remote into), but every time I try and run the web app I get this error. Why is code first not creating the database? Here's some relevant code.
Connection string in web.config
<add name="Context" connectionString="Data Source=Server\Instance;Initial Catalog=myDb;Trusted_Connection=false;User Id=User;Password=password;" providerName="System.Data.SqlClient" />
Global.asax relevant portion
Context context = new Context();
Database.SetInitializer(new MigrateDatabaseToLatestVersion<Context, Configuration>());
context.Database.Initialize(true);
if (!WebMatrix.WebData.WebSecurity.Initialized)
WebMatrix.WebData.WebSecurity.InitializeDatabaseConnection("BaseContext",
"UserProfile", "UserId", "UserName", autoCreateTables: true);
you're using integrated Windows authentication, you need to create a SQL Server login for "yourUser\ASPNET" on your SQL Server - or change your connection string to something like :
<add name="Context" connectionString="Data Source=Server\Instance;Database=myDb;Id=User;pwd=password;" providerName="System.Data.SqlClient" />
The login failed error is inside sql server error. Try if you have SQL Managment Studio logged using your data in connection string - Context.
I only thinking, but when you migrating your database recreate your user sql account and rester sql server.
Or
Try create new user by SQL Managment studio and then try usgin this data to connection string.
Check when you create user account, is not checked user must changed password first time.
I think my idea resolved your problem :)

The provider did not return a ProviderManifestToken string error

I am trying to create a web app using ASP.Net MVC3, Entity Framework and MySQL.
I have added the following code to my Web.Config file.
<connectionStrings>
<add name="ContactContext" connectionString="server=localhost;database=contacts;uid=root;pwd=password;" providerName="MySql.Data.MySqlClient"/>
</connectionStrings>
I also have created "Person" Model , "ContactContext" in the project "Contact_Me". When I try to create a "ContactController" including Person Model and Contact context, it gives me the following error
"Unable to retrieve metadata for "Connect_Me.Models.Persons". The
provider did not return a ProviderManifestToken string"
MYSQ & MVC3 SQL connection error \ ProviderManifestToken but I am using MySQL, this is the closest question to mine. But the answer didn't solve my problem.
Thanks in advance
I know this may be very basic for a couple of you guys, but this exception is also thrown in cases where EF is unable to locate a Connection String to use.
If you-re working in a multi-layered application, make sure the connection String is added to your client application, instead of the class library that contains you data access code.
Just my 2 cents.
I got this error when my sql server was actually down. So, please be sure that your sql server is up and running.
You can also get this error if you upgrade Nuget references in an EntityFramework project that uses MySql.Data.Entity (latest version is 6.10.X) and MySql.Data (latest version is 8.0.X). Those version numbers should match. You should use the MySql.Data.EntityFramework package with MySql.Data version 8.0 and after, and the MySql.Data.Entity package with versions 6.10 and before.
There are a lot more details in this blog post: https://davidsekar.com/asp-net/mysql-error-the-provider-did-not-return-a-providermanifesttoken
The problem was with the MySQL connector/Net.
I previously used MySQL connector/Net 6.3.5 and after I uninstalled it and installed MySQL connector/Net 6.5.4 the issue was fixed. You can find latest connectors at http://www.mysql.com/products/connector/
Sometimes this issue arises because of sslmode as well, For me the solution was to add sslmode=None to connection string
I had to make a small change to my connection string from
<add name="Connection" connectionString="Server=SOMEHOST;Database=DB;Uid=USR1;Pwd=PASS1;" providerName="MySql.Data.MySqlClient" />
to
<add name="Connection" connectionString="Server=SOMEHOST;Database=DB;Uid=USR1;Pwd=PASS1;sslmode=None;" providerName="MySql.Data.MySqlClient" />
May be the error is in your connection string. Have you tried to connect to your DB instance using the above log in. try changing the connection string
connectionString="Data Source=.;Initial Catalog=contacts;Integrated Security=True uid=root;pwd=password;" providerName="MySql.Data.MySqlClient"/>
use above if you are using sql server, else if you are using sql express use below one
connectionString="Data Source=.\SQLEXPRESS;Initial Catalog=contacts;Integrated Security=True uid=root;pwd=password;" providerName="MySql.Data.MySqlClient"/>
Even though this is answered, but I have experienced the same problem and my in case it was in the connection string; I had the part "Integrated Security" when I really shouldn't have used it; I was relying on the database authentication.
I removed the "Integrated Security=True" part and it worked perfectly :)
Restarting the computer worked for me.
While this message was showing, I did not find any differences between my computer [Windows 10] and the test server where the the application was deployed with the same configuration and was working correctly there and using the same database. It means the issue was probably not connected to the database running on the test server.
Worth mentioning is there were some Windows updates pending while restarting.

MVC 3 - After publishing to server - CREATE DATABASE permission denied in database 'master'

Setup
MVC 3 EF 4.1 Code First - Windows 7 Pro 64 Dev machine, Separate Win 7 Pro for host.
I started with a SQLCE4.0 database, and everything worked fine (database initializer created tables, populated, etc...).
Once I got everything working like I wanted, I scripted out my SqlCe DB, created a real SQL 2008 DB, opened the proper ports and enabled TCP connections.
Problem
IF I Change my connection string to point to my intranet server\instance name, with a user I created for this app specifically, it works perfectly running from my dev machine.
IF I publish the app to the server (the web server and sql server are the same), and I try to login to the website (aka access the db), then I get:
CREATE DATABASE permission denied in database 'master'.
I commented out the DBInitializer setup so nothing should be created upon a db hit. The tables are there already.
If I do Database.SetInitializer(null); then I get a different login error:
I don't remember exactly but it was something to the affect of LOGIN FAILED FOR IIS APPPOOL\ApplicationPoolIdentity
So I changed the Identity to NETWORK SERVICE and even tried LOCAL SERVICE, both giving the same login failed error.
I tried following this post who says add a SQL user named 'IIS APPPOOL\MyApplicationName'. SQL Wont let me do that as it has invalid characters ... go figure.
Why does it work perfectly over the network accessing the DB from my dev machine, but when I publish to THE SAME machine that hosts the sql and the site, I get permission denied or login failed errors? I've scoured the net and tried different things.
EDIT: Here are my connection strings:
<add name="AntripContext" connectionString="Data Source=|DataDirectory|AntripWeb.sdf" providerName="System.Data.SqlServerCe.4.0" />
<!--<add name="AntripSQL" connectionString="Data Source=.\sqlexpress;Initial Catalog=Antrip;User Id=myuser;Password=mypassword;" providerName="System.Data.SqlClient" />-->
<add name="AntripWebEntities" connectionString="metadata=res://*/DAL.AntripEntities.csdl|res://*/DAL.AntripEntities.ssdl|res://*/DAL.AntripEntities.msl;provider=System.Data.SqlServerCe.4.0;provider connection string="Data Source=|DataDirectory|\AntripWeb.sdf"" providerName="System.Data.EntityClient" />
<!--<add name="AntripWebEntities" connectionString="metadata=res://*/DAL.AntripEntities.csdl|res://*/DAL.AntripEntities.ssdl|res://*/DAL.AntripEntities.msl;provider=System.Data.SqlClient;provider connection string="Data Source=.\sqlexpress;Initial Catalog=Antrip;User Id=myuser;Password=mypassword;"" providerName="System.Data.EntityClient" />-->
Note: The commented out connection strings are the ones that use the sql 2008 database (that break my published app).
It sounds to me as if your connection string has Integrated Security=true so that you are connecting to SQL as the user you specify, rather than the SQL user you think you are using?
But beware, its still trying to create a database: you need to swap the IDatabaseInitializer - I guess it will look for a DB named the same as the entitys to be careful!