Aws RDS Connected via MySQLl Workbench but not Visual Studio - c#

I have an AWS RDS instance which I'm successfully connecting to via MySQL Workbench. However, I cannot connect to the RDS in Visual Studio (via connection string in Web.config) using the same credentials. Here, the connection times-out when I run update-database and gives: Error Number:53,State:0,Class:20, and error: 40 - Could not open a connection to SQL Server.
My connection string is in the following format:
<add name="ConnectionName" connectionString="Data Source=[NAME].[REGION].rds.amazonaws.com; database=[DB_NAME]; user=[USERNAME]; password=[PASSWORD]; Integrated Security=True" providerName="System.Data.SqlClient" />
Is there any issue with this connection string, or could I be missing something else entirely?
I don't have access to AWS Workbench, so I can't check any of the RDS settings, as the database was setup for me.

System.Data.SQLClient expects the other end to be a Microsoft SQL Server database, not a MySQL database. Instead you'll need to download and install a MySQL Managed Data provider and configure that as your provider:
See:
https://dev.mysql.com/downloads/connector/net/5.0.html
https://dev.mysql.com/doc/connector-net/en/connector-net-connection-options.html
Simplest way to get the MySQL Client distributed with your application is probably to use the NuGet package.
Example:
<add name="MySqlConnectionString"
connectionString="server=127.0.0.1;User Id=root;password=bpdash;database=sample"
providerName="MySql.Data.MySqlClient" />

Related

Switch from LocalDB to SQL Server DB MVC5

I have a MVC5 project with individual authentication.
Now I want to move from (localdb)\MSSQLLocalDB to another SQL Server database.
I've tried to change connection string from this :
Data Source=(localdb)\MSSQLLocalDB;Integrated Security=True;Connect
Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
to this:
Data Source=PC-GABRI;Integrated Security=True;Connect Timeout=30;Encrypt=False;TrustServerCertificate=False;ApplicationIntent=ReadWrite;MultiSubnetFailover=False
And the application is still using localDB instead of my new SQL Server DB.
I have already migrated the database and roles.
I have also tried to comment all of my connection string form Web.Config but my application is still working and I can login with my "test" user.
I can't find anything on the web about this!
PS.
Related Questions: Switch LocalDB to SQL server db with MVC5
We have the same problem!
UPDATE 1
DB Instance:
Connection String:
The instances are running correctly.
Tell me if you need more info.
UPDATE
This Guide was very useful for me :
https://danieleagle.com/2014/05/setting-up-asp-net-identity-framework-2-0-with-database-first-vs2013-update-2-spa-template/
Follow all the easy steps for move your LocalDB table to SQL server db Table.
1. Inspect the Web.config File Connection String and Connect to Local Database
Change the defaut connection string:
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\MSSQLLocalDB;AttachDbFilename=|DataDirectory|\aspnet-WebApp-20190226025646.mdf;Initial Catalog=aspnet-WebApp-20190226025646;Integrated Security=True" providerName="System.Data.SqlClient" />
To your connection string:
<add name="DefaultConnection" connectionString="Data Source=PC-YWGSB;Initial Catalog=WebApp;user id=admin;password=admin" providerName="System.Data.SqlClient" />
2. Then use the commands for DB Migration "Codefirst"
This is the official guide:
https://learn.microsoft.com/it-it/aspnet/mvc/overview/getting-started/getting-started-with-ef-using-mvc/migrations-and-deployment-with-the-entity-framework-in-an-asp-net-mvc-application
From the Tools menu, select NuGet Package Manager > Package Manager Console.
At the PM> prompt enter the following commands:
enable-migrations
add-migration InitialCreate
update-database
The database will be created automatically during migration.
If you already have one make sure to backup all tables.

ServerVersion = 'conn.ServerVersion' threw an exception of type 'System.InvalidOperationException'

I've seen this error answered for other people, but I can't seem to get it to work. I'm trying to connect to a SQL Server Database project locally.
I'm getting this error thrown on Open() when I do the follow:
SqlConnection conn = null;
conn = new SqlConnection(connection)
conn.Open()
Where connection is a connection string passed from my webconfig. I've found examples online and tried these three connection strings and I get the same error every time:
<add name="TICKETING_CONNECTION" connectionString="Server=(local); DataBase=Ticketing_DB; Integrated Security=SSPI"/>
<add name="CONN"
connectionString="Data Source=localhost; Integrated Security=SSPI;Initial Catalog=Ticketing_DB"
providerName="System.Data.SqlClient" />
<add name="CONN2"
connectionString="Data Source=(local);Initial Catalog=Ticketing_DB;"
providerName="System.Data.SqlClient"
/>
Could the problem be stemming from the path of where the database is located on my machine? I've tried copying the c:\ path but didn't have any luck. I've seen some examples online use a .mdf file, but my project does not have this file either.
This is my first time trying to connect to a database project, so any help or advice would be greatly appreciated
If you are using Visual Studio try going to the Server Explorer and Right click on Data Connections and Add new connection by selecting DataSource as Microsoft SQL Server and provider as .net framework provider for SQL Server.
Under the server name check for the SQL Server if it is listed with your machine name.
Then try to provide the database details and user name and password for SQL Authentication or select windows for windows authentication. Then do a test connection. If it is fine on click of OK it will add the data connection.
Right click the properties of data connection which is newly added and navigate to properties to extract the connection string. Compare it with yours. This can help you troubleshoot the issue.

C# Remote Connectionstring SQL Server

ich got some problems connecting to the database stored on a server in the local network. I tryed almost everything, but nothing helps.
I got 2 Databases, MYSQL and MSSQL.
Configuration:
Server: 192.168.0.198
MYSQL Port: 3306
MSSQL Port: 1433
If i connect manuelly in Visual Studio it works, but if i copy the ConnectionString from the properties, it only connects to the MYSQL Database and not the MSSQL (same login, same password, same ip adress, but ports are different)
In Visual Studio is P3B-Server\P3BMSSQL for the server and db_Software for the database
Visual Studio Properties:
"Data Source=P3B-Server;Initial Catalog=db_Software;User ID=myUser;Password=mypassword"
But it doesnt work :/
I tryed
"Data Source=P3B-Server..."
#"Data Source=P3B-Server\P3BMSSQL..."
"Data Source=192.168.0.198,1433..."
"Data Source=tcp:192.168.0.198,1433..."
Still no connection to MSSQL Server, only MYSQL Server.
I`m connecting with HeidiSQL to both Databases and got
"Microsoft SQL Server (TCP/IP, experimental)" with 192.168.0.198, Port 1433,
user=myUser and Password=mypassword" for the MSSQL Server and there it works.
Checked "connectionstrings.com", but no solution works for me.
PS: Other side is an ASP.NET application, which connects with
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=192.168.0.198;Initial Catalog=db_Software;User Id=myUser;Password=myPassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>
(stored in Web.config) to the database.
I need exact this for my C# application as a Connectionstring.
Please help me. Thanks !
<connectionStrings>
<add name="ApplicationServices" connectionString="Data Source=192.168.0.198\P3BMSSQL;Initial Catalog=db_Software;User Id=myUser;Password=myPassword;" providerName="System.Data.SqlClient"/>
</connectionStrings>

Entity Framework Connection to localDb

I am trying to follow the pluralsight course ASP.NET MVC 4 Fundamentals. But can't have my database connected.
Here is the error I got:
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.
I have visual studio 2013 professional and SQL server 2012 installed on my machine. When I installed my SQL server, I created a server name "ABC" on my computer.
I have also installed sql localdb 11.0 separately, but it seems VS can't find the localDb connection. When I check Server Explorer -> add Connection, under server name list, only "ABC" is shown up.
Here is the connection string.
I also tried to use "Data Source = ABC; ...." it doesn't work either.
Update
Here is my connection string
<add name="DefaultConnection" connectionString="Data Source=(LocalDb)\v11.0;Initial Catalog=aspnet-eManager.Web-20141223223418;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|\aspnet-eManager.Web-2014122322341‌​8.mdf" providerName="System.Data.SqlClient" />
You could try this
In server explorer, right click, Choose Add Connection
enter (localdb)\v11.0 in as the server name
Choose your database and press connect
Right click properties on your new connection
Use that connection in string in your default connection
I.e.
<add name="DefaultConnection" connectionString="<Paste-connection-string-here>" providerName="System.Data.SqlClient" />
If that doesn't work, lets try starting it from the command line
Open command prompt
Run SqlLocalDB.exe start v11.0
Follow original steps , use the named pipe as your server name
If that doesn't work, lets try and connect via named pipes
Open command prompt
Run SqlLocalDB.exe info v11.0
Copy the Instance pipe name that starts with np:...
Follow original steps , use the named pipe as your server name
e.g
Run this command to make sure what is the version of your LocalDB
sqllocaldb info
So in my case the version is MSSQLLocalDB then the connection string will look like this
<add name="DefaultConnection" connectionString="Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=IdentityManagerDB;Integrated Security=True"
providerName="System.Data.SqlClient" />
To add on to TheGeneral use view - SQL Server Object Viewer and look immediately under the "SQL Server" object. You'll see the name of the connect looking something like "(localDB)\ProjectsV13" Hand enter that into the connection box then you can browse the server for the database you want to use.

C# Linq-to-sql server name when creating a release

I'm working on C# linq-to-sql application over SQL Server express 2008 . My database is inside SQL server.
I'm using Windows Authentication to connect to sql server from my application.
The server name used in connection string is related to my pc user name, so I'm wondering if I create a release of my application and put it on client pc which have SQL Server installed with another server name, would my application work?
my connection string is
<add name="WindowsFormsApplication1.Properties.Settings.OPTICA_MDFConnectionString"
connectionString="Data Source=ENG-MEDIAN-PC;Initial Catalog=OPTICA.MDF;Integrated Security=True"
providerName="System.Data.SqlClient" />
Because the app and the sql server are on the same host you can use "Data Source=.\<instance name>" which may be the default MSSQL.
That default would look like this:
connectionString="Data Source=.\MSSQL; ... "
For another example, our developer boxes' app.config uses this:
connectionString=".\DEVSQL;Initial Catalog=..."
Note that the "." is the host and that "DEVSQL" is the sql server instance name.

Categories

Resources