I'm trying to connect to a SQL Anywhere 10 database using an ODBC connection in C#. This connects fine with all the default parameters, but whenever I try to specify a port or IP address, it looks like it's completely ignored
My connection string is:
Driver={SQL Anywhere 10};uid=username;pwd=password;
Which works when connecting to the first database listed. I want to connect to the second database running on the computer, which is on a different port. I have tried:
Driver={SQL Anywhere 10};uid=username;pwd=password;port=1234;
Driver={SQL Anywhere 10};uid=username;pwd=password;LINKs=tcpip(host=192.168.1.1:1234)
Driver={SQL Anywhere 10};uid=username;pwd=password;DataSource=localhost:1234;
None of these have changed the connection at all, or even failed to connect
What is the correct string to use to specify port?
Or what other method can I use other than a System.Data.ODBC.ODBCConnection to connect where I can specify a port?
It looks like you're just making up connection attributes to try in the string...
Try looking at documentation for the driver you're using --
Driver={SQL Anywhere 10};UID=<user name>;DatabaseName=<database name>;EngineName=<database engine name>;AutoStop=YES;Integrated=NO;EncryptedPassword=3ff6c3114e;Debug=NO;DisableMultiRowFetch=NO;CommLinks='TCPIP{HOST=<database server name>;PORT=<port number for remote connections>}';Compress=NO
Most of those attributes are optional, so here's a reduced string that may work for you --
Driver={SQL Anywhere 10};UID=username;PWD=password;CommLinks='TCPIP{HOST=localhost;PORT=1234}'
Related
I have recently installed MySQL on our local server, and I am attempting to connect to it using this connection string:
mySqlConnectionString = "server=192.168.1.254;database=dcim;uid=root;pwd=LlmD62jL;";
I have also tried adding the port as well:
mySqlConnectionString = "server=192.168.1.254:3306;database=dcim;uid=root;pwd=LlmD62jL;";
But I still keep getting the MySqlException:
1042 - Unable to connect to any of the specified MySQL Hosts.
I have tried with the Firewall active and de-activated, but nothing has worked so far. What's going on?
EDIT: I thought I should note that I used this connection string to connect to MySQL on the same machine, with no problems using localhost or 127.0.0.1.
NB: This is MySQL Server with .NET Framework connection.
First check mysql server is working or not.
Try to add port number of mysql in connection string(The port 3306 is the default MySql port).
Check spacing and Order of parameters in connection string.(Sometimes it matters base on my experience",) )
Here's the basic format you could follow:
Server=ServerAddress; Port=1234; Database=DataBase; Uid=Username; Pwd=Password;
Also try to read this article its useful for connection strings. MySQL connection strings
Hope it helps. ",)
I am creating desktop application in c# but i wont to use Online Database created in mysql.
String mysqlConnectionString = "Server=216.14.120.105;Database=xxx_keys;UID=xxx_root;Password=xxx;Port=3306";
MySqlConnection connection = new MySqlConnection(mysqlConnectionString);
connection.Open();
this is the code i am using but i got an error unable to access host.
where i am wrong and if you have any proper code or details then give me.
If this is a MySQL database in local server user "localhost" for server IP as georgi-it also told. But if this is an external database first try to open a telnet connection on dos-prompt to see if there is some firewall block or something like that:
telnet 216.14.120.105 3306
if you don't get an error message and see a blank page then it means you can reach mysql server
What connection string should I use if SSMS connects to it using simply machine name, without instance name?
I mean it connects using the following string: PCName
I used to connect using PCName/SQLExpress. I cannot set correct connection string in my app in order to connect app to database on this machine.
How can I check what data source I should use? I've checked in Sql Server configuration that server instance named as SQLEXPRESS.
So I tried data source as:
.\SQLEXPRESS
PCName\SQLEXPRESS
.
I'm trying to connect to a service-based database, located in my app folder. So I'm using the following connection string:
data source=PCName;attachdbfilename=|DataDirectory|\spareparts.mdf;integrated security=true;user instance=true;multipleactiveresultsets=true;App=EntityFramework;
If SSMS connects via PCName then your application should be able to use Data Source=PCName. However it depends on whether your application is on the same machine as SSMS or not. If on a different machine it might not be able to connect for a variety of reasons. We can't speculate what the problem might be if all you do to describe the issue is "It won't connect" - what does that mean? Do you get an error message? If so, what is it? Make sure:
SQL Browser service is started
TCP/IP is enabled
Add Network=DBMSSOCN; to the connection string
You've also tried the IP address in addition to PCName
Firewall isn't blocking the SQL Server port
I have one problem with C#
I connect Data Source=BARIS;Initial Catalog=SurucuOtomasyon;User ID=sa;Password=1234
But I don't connect database when i write mylocal ip to Data Source
Data Source=192.168.1.3;Initial Catalog=SurucuOtomasyon;User ID=sa;Password=1234
Thanks for helping
an answer
Open your SQL Configuration Manager and allow to TCP/IP connections.
Set dynamic port blank to disable it (i don't remember here well)
The IP gives the machine, you need a port, too:
192.168.1.3:1433 (the port 1433 is a standart)
another link about connectionstrings
connection string with DataSource=192.168.2.3 is enough. You have to change configurationn.
Right configuration will run your code. (i've tested it with a project, its all about configuration of your sql. See my comment below)
I have had difficulty creating a connection string in c# that will connect to a remote SQL server using a public IP, named instance and a port number (other than 1433). Anyone know how to do that?
Try this, replacing 666 with the port number you want to use, 190.190.200.100 with the IP address you want, etc.:
Data Source=190.190.200.100\MyInstance,666;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;
Using the servername tcp:<public IP>,<port>, as documented in SqlConnection.ConnectionString:
The name or network address of the
instance of SQL Server to which to
connect. The port number can be
specified after the server name:
server=tcp:servername, portnumber
When specifying a local instance,
always use (local). To force a
protocol, add one of the following
prefixes:
np:(local), tcp:(local), lpc:(local)
Data Source must use the TCP format or
the Named Pipes format.
TCP format is as follows:
tcp:<host name>\<instance name>
tcp:<host name>,<TCP/IP port number>
If you use the tcp:<host name>\<isntance name> the SQL Browser service connection is required (port 1433) therefore is better to use the later format, with explicit port name:
Data Source=tcp:1.2.3.4,1234;User Id=...; Password=...
This site has never failed me.
And i am gonna state the obvious here, but it is generally a bad idea to expose your sql server on the internet.. (unless you are using VPN)
connectionString="Database=pub;Server=192.168.1.1\INSTANCE,1746;Trusted_Connection=yes;"
Or you could use username/password instead of trusted connection.