What should be the proper structure of Connection string in C# to access SQL Server 2008 R2 over internet using the public ip of the server ?
I used the below connection string . It works fine within our network using local IP but when i am trying to acces it over internet with public IP, I am getting error.
SqlConnection con = new SqlConnection("Data Source=tcp:192.168.0.16,49582;Initial Catalog=TrulyDB;uid=sa;pwd=sa#pass123;");
There are different ways to Create Connection String which depends on
Authentication type as you know
1.> Windows Authentication
2.> SQL Server Authentication
Follow this link
SqlConnection con = new SqlConnection("Data Source=192.168.0.16,49582;Network Library=DBMSSOCN;Initial Catalog=TrulyDB;uid=sa;pwd=sa#pass123;");
Related
So I'm developing an application for my school in C#. I need to know how to connect via a proxy server to the MySQL database. I've been having a look around and found the following code:
NetworkCredential credential=new NetworkCredential("User","Password");
WebProxy proxy=new WebProxy("10.0.0.1",808);
proxy.Credentials=credential;
MySqlConnection conn = new MySqlConnection();
conn.ConnectionString = "Host=192.168.0.10;port=3307;user=root;password=root";
conn.Proxy=proxy;
However, the line conn.Proxy=proxy; doesn't work as conn doesn't contain a definition for Proxy.
So how do I connectt to MySQL through a proxy in C#?
For anyone else having the problem, this is how I got around it:
http://www.hanselman.com/blog/HTTPPOSTsAndHTTPGETsWithWebClientAndCAndFakingAPostBack.aspx
I'm trying to connect to a remote SQL Anywhere 10 database server using the following connection string but receiving a "Database Server Not Found" error.
OleDbConnection conn = new OleDbConnection("Provider=SAOLEDB.10;ENG=dental;DBN=dentserv;
LINKS=tcpip(host=192.168.1.100,PORT=2638);
Integrated Security = True; User ID = dba; PWD = sql");
Using the same code, I can connect to a local database that is setup the same way as the remote server I'm attempting to connect to without any issue:
OleDbConnection conn = new OleDbConnection("Provider=SAOLEDB.10;Data Source = dental;
Database=dental;Integrated Security = True; User ID = dba; PWD = sql");
I've added and removed multiple variables within the string to troubleshoot to see if there was anything missing (ENG instead of Data Source, with and without DBN, DSN, etc.), most seem to be interchangeable but always throwing the same error of no server.
For some additional information, I am able to connect to this server database using a different database management tool using the same port IP credentials with no issue. It's Database URL is: jdbc:sybase:Tds:192.168.1.100:2638?ServiceName=
Connection String:
DBN=DENTSERV;DSN=DENTAL;UID=DBA;PWD=SQL
Any thoughts? I've been working on this for awhile with no further progress. Any insight will be much appreciated!
The host (host=192.168.1.100); appears to be a private IP (IP for your local network), you cant use that for remote access you may use a Public IP also the server need to be configured for remote access.
I moved from SQL Server 2014 to SQL Server Express (free version) and since then I can't connect to database using SqlConnection with IP.
I can connect local with connection string but when I am using an ip address I get error number 10061, I checked whole net about that error and verified all the issues mentioned: remote connection is allowed, I added port in firewall, enabled tcp in server...
In official version of SQL Server it works fine, but when I moved to EXPRESS free version I can't successfully connect remotely any more.
This is the connection string I use:
SqlConnection cn = new SqlConnection(#"user id = ***; password=***;server=192.168.1.102,1433; Trusted_Connection=no; database=myDatabase; connection timeout=30");
Getting exception error number 10061.
But when I use the local connection string:
SqlConnection cn = new SqlConnection(#"server=ASUS\SQLEXPRESS ;database=myDatabase;user id = ***; password=***;");
That works fine...
What can the problem be?
You still need to specify the instance name when switching to using the I.P to connect.
SqlConnection cn = new SqlConnection(#"user id = ***;
password=***;
server=192.168.1.102\SQLEXPRESS;
Trusted_Connection=no;
database=myDatabase; connection timeout=30");
I should have set the port and ip in server configuration manager.
When I change my sql server Connection to:
SqlConnection dbConn = new SqlConnection("Data Source=localhost; Initial Catalog = Semester 2 Project SD; Integrated Security=SSPI");
It gives me an error saying that it cant find the server or can't connect to it.
Is my string/ sql connection completely wrong or is there anything i need to change in SQL server, or both?
When I use server = BACON1-PC\\SQLEXPRESS it works completely fine though.
I have some problems with connecting to my local DB using c# System.Data.SqlClient.
Information:
DB parameters: Name:baza Host:localhost Instance:baza Port:3306 Schema:world
My connection string: #"server=localhost\baza;password=pass;User Id=root;database=world;Persist Security Info=True"
using: c#, System.Data.SqlClient, MySQL Workbench
firewall off
succesfull conection with JDBC, so server is working
JDBC parameters:
String url = "jdbc:mysql://localhost:3306/";
String driver = "com.mysql.jdbc.Driver";
String dbName = "world";
String username = "root";
String pass = "pass";
Problem:
when I use conn.Open(); this happen => (provider: SQL Network Interfaces, error: 26 - Error Locating Server/Instance Specified)
Tried:
server=localhost then it gives => error: 40 - Could not open a connection to SQL Server
many other stupid combinations like server=baza
http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx
ASP.NET beginner question: How to get rid of this error?
Connection to freesql.org server also failed
I have no idea what to do... Sth is probably with server name.
EDIT:
code:
string connstr = #"Data Source=localhost\baza;password=qspass;User Id=root;"+
"Initial Catalog=world;Persist Security Info=True";
Console.WriteLine(connstr);
SqlConnection conn = new SqlConnection(conbuild.ConnectionString);
conn.Open();
Console.WriteLine("YO!");
Some more code...
Never reached YO! :P
I suppose I should put my answer in the answer section, rather than a comment :)
I see from your JDBC connection string that you are using MySQL rather than SQL Server.
The System.Data.SqlClient namespace is the.NET Framework Data Provider for SQL Server, not MySQL.
If you are using MySQL, you will need to use the MySQL ADO.NET driver available here:
Download Connector/Net