Im trying to connect to a mysql database running on openshift.
The computer I have used is running win 10.
Below is my C# code snippet of what im trying to do. The server address, password, and username have been blanked out.
string connStr = #"Server=xxxxxxx.rhcloud.com:3306;Database=hurnhusms;Uid=XXX;password=XXX;";
SqlConnection conn = new SqlConnection(connStr);
try
{
Console.WriteLine("Connecting to MySQL...");
conn.Open();
Console.WriteLine("Connection successfull !");
conn.Close();
Console.ReadLine();
}
catch (Exception ex)
{
Console.WriteLine("error => " + ex.ToString());
}
Console.ReadLine();
when I run the application all I get is:
System.Data.SqlClient.SqlException (0x80131904): 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.
i have also ran rhc port-forward , i have also pinged the mysql port on the site and it is open.
Any help would be appreciate.
Okay what I figured out is that I need to execute the rhc port-forward and then keep that window open (not terminate that command). I didn't realize that window need to stay open.
Related
i have SQL server express 2012 installed on windows 10 64 bit, the connection from same computer worked fine, problem when i connect from another computer on same network,
i get error message:
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 connection
-provider TCP provider error 0 the wait operation timeout
i try the following things but not fix the problem:
Enable and automaticly start SQL Browser
Enbale TCP/IP and set port 1433 for all IP types
Start Named inslance SQLExpress2012 autmaticaly as Build-in : Network service
connect without user and password with IntegratedSecurity=true
The database is using mixed-mode authentication
add an exception in the firewall for port 1433
enable named pipe
allow remote connection
this is my code:
public static bool TestSQLServerConnection(
string ComputerNameOrIPAddress,
string SQLServerInstanceName,
string PortNumber)
{
try
{
SqlConnectionStringBuilder SQLServerConnectionString = new SqlConnectionStringBuilder();
SQLServerConnectionString.DataSource = ComputerNameOrIPAddress+",+"+PortNumber+"\\"+SQLServerInstanceName;
SQLServerConnectionString.InitialCatalog = DatabseName;
SQLServerConnectionString.TrustServerCertificate = true;
SQLServerConnectionString.IntegratedSecurity = true;
//SQLServerConnectionString.UserID = "...";
//SQLServerConnectionString.NetworkLibrary = "DBMSSOCN";
//SQLServerConnectionString.Password = "...";
SqlConnection con = new SqlConnection(SQLServerConnectionString.ConnectionString);
SqlCommand cmd = con.CreateCommand();
cmd.CommandType = CommandType.Text;
cmd.CommandText= "select 1";
con.Open();
cmd.ExecuteScalar();
con.Close();
return true;
}
catch (Exception ex)
{
throw ex;
}
}
when i ping the ip address or computer name of computer of SQL Server it connected and return response, means the computer is connected to network.
i search for while without any solution, please help me.Thanks
I add
SQL Browser Service UDP Port 1434 on firewall and worked fine.
Use SQL Server Management Studio to connect remotely to an SQL Server Express instance hosted on an Azure Virtual Machine
I have a C# Xamarin Android application which I need to connect to a SQL Server instance accessible over the network.
try
{
using (SqlConnection cn = new SqlConnection(ConnectionString))
{
cn.Open();
IsConnected = true;
}
}
catch (Exception ex)
{
Toast.MakeText(Application.Context, "Error Occuerred: " + ex.Message, ToastLength.Long).Show();
}
The Connection String is as follows: Data Source=IPAddress;Initial Catalog=DatabaseName;Persist Security Info=True;User ID=SomeUser;Password=SomePassword
I have included the INTERNET and WIFI_State Permissions in the manifest. (To check if wifi is currently turned on and connected to some kind on network)
I am getting an error: Server Does Not Exist or Connection is refused.
I can connect my Honeywell Scanning device to the database with the same connection string.
Please NOTE I don not want a web service to handle the SQL connection in order for me to select and update tables.
Wrote an ASP. NET web service which is very efficient and quick
I'm facing some issues trying to connect to an SQL Server 2005 using Entity Framework.
I've this small WindowsForm application using a System.Data.SqlClient.SqlConnection:
SqlConnection cnn = new SqlConnection("Data Source=servername\\sqlhotel;Database=mydatabase;User Id=myusername;Password=mypassword");
try
{
cnn.Open();
MessageBox.Show ("Connection is Open ");
cnn.Close();
}
catch (Exception ex)
{
MessageBox.Show("Can not open connection ! ");
}
This is working fine on my server (I'm getting the "Connection is Open" message), but in my ASP.NET Web API application using Entity Framework 6 I'm getting this error using the above connection string:
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)
Why?
Ensure that TCP/IP is enabled in SQL Server Configuration Manager, and that SQL Server is allowed through your Windows Firewall (on the server) if you are trying to connect remotely. You can add it to the white list if not, but for security reasons this is probably a bad idea - and definitely a bad idea if it is a production server.
I am developing an application that runs on windows Ce 6.0, the application should connect to a database that is located on my PC., but every time I try to open the connection i get A SQLException error message. this is how I am opening the connection
..........
SqlConnection EdiSqlConnection;
String ConnectionString;
ConnectionString = "Server='serverName';Database=DatabaseName;Trusted_Connection=true;";
..........
EdiSqlConnection = new SqlConnection(ConnectionString);
try {
EdiSqlConnection.Open();
Output.Text = "Connected"; //this is a message to see that we are connected
}
catch (Exception ex) {
Output.Text = "Message: " + ex.Message;
return;
}
Why am I getting the error message? and how do i resolve it?
Thank you.
There isn't enough information here, so you'll need to provide more.
What type of exception is being thrown? Are you Sure its a SqlException? You are catching all exceptions.
What is the value of ex.Message in the catch block?
Which database are you connecting to? SQL Server (version?) or SQL Compact?
Assuming your application and the database are running on separate machines, you may have problems with trusted connection. Your WinCE device is unlikely to be on a domain or have a way to authenticate a user, so authentication will probably fail. Try using SSPI authentication instead. See "Trusted Connection from a CE device" on this page. Note that you don't have to give a domain user ID, just a user ID and password that is valid on the database server machine and which has access rights for the database.
remove the quotes from 'serverName'
I'm writing an application that uses a SQL Server 2005 database. In the connection string I'm specifying the mdf file like this:
connstr = #"Data Source=.\SQLEXPRESS; AttachDbFilename=" + fileLocation + "; Integrated Security=True; User Instance=True";
When I execute the code:
public static void forceConnection()
{
try
{
conn = new SqlConnection(connstr);
conn.Open();
}
catch (Exception e)
{
MessageBox.Show(e.Message, "Erro", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
finally
{
if(conn != null)
conn.Close();
}
}
I receive an exception:
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)
This code works on XP but not in Vista. I tried to run Visual Studio in admin mode and moved the mdf file to "user data" folders but the error persists.
Any help?
Can you connect to the sql server db in your command prompt? I would make sure you can actually connect first.
Try open the cmd prompt and type sqlcmd -S .\SQLEXPRESS -d your_dbase
If I have mssql-connect problems with my dotnet-sourcecode I try to connect to the database with a different program. I use queryexpress that is also written in dotnet. If this program works then I know that the problem is with my program code else the problem is with connection string, proxy, network, sqlserver or user permissions.
Do you actually have sqlexpress installed? does it use the machineName\sqlexpress or does it run as a default instance?
You have to verify these cases.
and you might wanna use the actual machineName\instance name if you aren't using the default instance.