I am trying to use visual studio to write a program in c# and have it connect to my google cloud sql server. Unfortunately I have been trying to troubleshoot it and have had no luck. I already added my IP and my connection works through MYSQL Workbench.
I attempted to connect with the whole data source, network library, initial catalog, etc. I tried it without the network library and used the proper way to escape \ in the string during the connection. I also tried the default 1433 port and 3306. No luck.
// Build Connection String
SqlConnection clearviscon = new SqlConnection(#"Server=xx.xx.xx.xx\alpine-park-243102:us-central1:xxx, 3306;Network Library=DBMSSOCN;Initial Catalog=xxdatabase;User ID=root;Password=xxx123");
clearviscon.Open();
To connect to Google Cloud SQL for MySQL, you must use a MySQL client library. I recommend MySqlConnector.
Your connection string will be Server=xx.xx.xx.xx;Database=xxdatabase;User ID=root;Password=xxx123.
If you're using a client SSL certificate to connect to your server, add this to the end of your connection string: ;SslCa=server-ca.pem;SslCert=client-cert.pem;SslKey=client-key.pem.
You must use MySqlConnection.
See this link for more information: https://cloud.google.com/dotnet/docs/getting-started/using-cloud-sql
i am developing an app where i am having a common sql server database .mdf put on a LAN Server which is needed to be connected to two or more different instances of a same application as other stations.
i am able to select the database but it is giving me and error posted below:
how to overcome this? the connection string is
connectionString = #"Data Source =(LocalDB)\MSSQLLocalDB; AttachDbFilename = " + path + "; Integrated Security = True; Connect Timeout = 30";
P.S. it is working when a single instance is connected to it and it is preventing the second or third app to use it.
any help will be appreciated.
You need to host the database on a network server. Several clients can connect to a SQL Server. But several clients cannot simultaneously connect directly to an MDF file.
The file alone cannot handle the concurrency. You need to have an application for it. That's where SQL Server comes into play.
After hosting, you need to change your connection string as well. Then it should work.
connectionString="Data Source=ServerName;Initial Catalog=DatabaseName;Integrated Security=True;MultipleActiveResultSets=True"
What is the best way to connect remotely to MySQL server on domain ?
I want to make an desktop app or maybe it is easier to do it with asp.net ?
Use Mysql Workbench for desktop use to connect to Mysql Server.
For coding: Get Mysql client library for .net . It's called mysql connector. Add
using Mysql.Data; namespace
https://dev.mysql.com/doc/connector-net/en/connector-net-programming-connecting-open.html
Makes no difference what kind of application you are creating.
your code will look very similar like this one:
MySql.Data.MySqlClient.MySqlConnection conn;
string myConnectionString;
myConnectionString = "server=127.0.0.1;uid=root;" +
"pwd=12345;database=test;";
try
{
conn = new MySql.Data.MySqlClient.MySqlConnection(myConnectionString);
conn.Open();
}
catch (MySql.Data.MySqlClient.MySqlException ex)
{
MessageBox.Show(ex.Message);
}
1- I usually use HeidiSQL tool to connect to MYSQL server otherwise on localhost or remotely servers on CPanels.
most of CPanels allow to remote connection by adding % at access hosts field to enable me connect remotely anywhere.
from your cpanel go to the database tools then -> you will find link for Remote mysql -> then you can any IP address to make server allow to connect, if you want connect anywhere you put %.
Note: CPanels are little different each others.
2- if you want connect to mysql in your code, you make a normal connection after doing step 1.
I have installed postgresql database in http://postgres-project-1241043.j.layershift.co.uk/ host.
I want to connect to the database using C#. I use Npgsql with following connection string.
connectionString = # "Server = postgres-project-1241043.j.layershift.co.uk, Port = 5432, User Id = postgre; Password = abcdef; Database = dbluanvantn;";
But I am not able to connect to the server and get error:
Npgsql.NpgsqlException: Failed to a connection to
'postgres-project1241043.j.layershift.co.uk'.
Am I using correct connection string?. Help me fix it.
You can only connect to Postgres (on our Jelastic service) if you add a public IP to the node first. Without that step, you can only connect to it locally (i.e. from another server within your Jelastic environment).
Also I want to mention that you are always welcome to contact our support team (our tech. support is 24x7 and completely free; even for our trial accounts) if you need any further help.
My sqlconnection is
SqlConnection(#"Data Source = John\Administrator; Initial Catalog = TicketingSystem; Integrated Security = true;");
I try to connect to the server but i cant this error pops up
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 think that the error is in the Data Source but I cant find it. When I open Microsoft SQL Server Management Studio it says that my server is "John" and the Connection is "John\Administrator" so please help me.
if the server is actually called 'John', then that is your data source. When you're running locally, you could probably just set Data Source=(local), tho.
Other than that, you'd need to specify a user to connect with
http://connectionstrings.com/
An easy way to get your connection string is
create a file called x.udl
double click on it
Follow wizard
open x.udl file in notepad
and inside you will find your connection string.
When I open Microsoft SQL Server
Management Studio it says that my
server is "John" and the Connection is
"John\Administrator" so please help
me.
That means you're logged on to your server's default instance (John) as Administrator. Remove the \Administrator part, and you should be good to go!
var cn = new SqlConnection(#"Data Source = John; Initial Catalog = TicketingSystem; Integrated Security = true;");
You can get your connectionstring from SQL Server Management Studio from the properties window.
Just click on the John\Administrator node, then press F4 to open the properties window, and search for the connection string there...
The Integrated Security=True part of your connection string means "connect as the current user". When you run an asp.net page, the current user by default is a special ASPNET account. You can "impersonate" a different user, but I'm guessing you haven't done that and the ASPNET user doesn't have access to your database.
It's possible that your server isn't configured to allow remote connections. You can check this in the SQL Server Configuration Manager tool.
Have a look here too.
Your Data Source is the server. So you only need "John", not "John\Administrator", that's not a valid data source. You're using integrated security which means it will use the same username as the program is running under and it's credentials, if it's on the domain.
Data Source = John\Administrator
Specifying John\Administrator as your Data Source, means ADO should connect to the SQL instance named "Administrator" on the server "John". Although instances are quite useful, I don't think that's what you want. (SQL Instances allow you to run multiple copies of SQL Server on one server)
As "d." mentioned, you will need to change Data Source to the correct server name or (local) ((local)\SQLEXPRESS if it's SQL Express).
Also, Integrated Security=true means that the user running ASP.NET, or at least the AppPool, will need access to the database. (The default is NETWORK SERVICE on pre-Windows 7, IUSR / IIS_USRS on 7).
If, however, you use ASP.NET windows authentication with <identity impersonate="true" /> then the user accessing the site will need access to the database.
Create a file called x.udl
Double-click on it
Follow the Wizard
Open x.udl file in notepad
and then you will find your connection string inside.