Well, after doing some research i created a database in MSSql server (2014) and can get a connection via sqlconnection with client, by using:
SqlConnection cn = new SqlConnection("user id = myUSER; password=myPASSWORD;server=mySERVER; Trusted_Connection=yes; database=myDatabase; connection timeout=30");
The connecion exist when my client is local and run on the same machine as MSSQL server, but when i'm on a remote pc i can't connect to the MSSQL server using sqlconnection.
How can i connect to that server from remote using sqlconnection - c# ?
Most likely, your SQL Server is not configured to allow remote connections, as Sean Lange points out in one of the comments above.
Carry out these steps from the Management Studio:
Right-click on the server name, click on 'Properties'. You'll get the 'Server
Properties' window.
Click on the 'Connections' tab in the left of this
window
You'll see a section on the right, that says 'Remote server
connections'
Check the 'Allow remote connections to this server'
checkbox.
Related
I know how to connect to SQL server Management studio locally, the one to your desktop, Windows Authentication. Code is as below.
myconnection As New SqlConnection("data source =serverNAME01; initial catalog=ZPCD; integrated security=true")
But how do I connect to SQL server Management Studio on Windows Server 2012R2, SQL Server Authentication from my desktop ?
The computer and username for remote desktop connection to Windows Server 2012R2 are:
computerNAME01,
userNAME01
The server name, login, password and IP address to management studio (database engine) are:
Server name: serverName01
Login: sa
Password: Password01
IP: 192.167.1.21
and database name is
ZPCD
This is an example of my code, but it doesn't work.
connetionString="Data Source=192.167.1.21,1433;
Network Library=DBMSSOCN; Initial Catalog=ZPCD;
User ID=sa;Password=Password01"
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 connections. (provide: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server) (Microsoft SQL Server, Error: 5)
https://technet.microsoft.com/en-us/library/hh231672(v=sql.110).aspx
To enable the TCP/IP network protocol Start SQL Server Configuration
Manager. Click Start, point to All Programs, and click Microsoft SQL
Server. Click Configuration Tools, and then click SQL Server
Configuration Manager. In SQL Server Configuration Manager, in the
console pane, expand SQL Server Network Configuration. In the console
pane, click Protocols for . In the details pane,
right-click TCP/IP, and then click Enable. In the console pane, click
SQL Server Services. In the details pane, right-click SQL Server
(), and then click Restart, to stop and restart the SQL
Server service.
Remote connection string should look like so.
SqlConnection("Server=192.167.1.21\sqlinstance; DATABASE=ZPCD; Connection Timeout=5; USER ID=SA; PASSWORD=Password01")
You need to have the SQL instance, the part in the () in image below after the \ after the IP address.
Can you post this from SQL Management Studio
This is the format of the connection string I use. The format (apparently) changed in VB.NET from VS 2008 to VS 2010. When I upgraded my software from VS 2008 to VS 2010, it failed to connect to Sql Server. Took me hours to figure it out:
connectionString="server=192.168.1.1;database=MyDb;uid=sa; pwd=MyPassword" providerName="System.Data.SqlClient"
R/
Prescott ....
I want to test a connection using SQL Server that can access through internet but I'm lost, I don't know where to start.
I know how to do it in MySQL but I want to know how to do it in SQL Server.
Thanks in advance.
One quick trick I know of, which works even on machines without SQL tools installed:
Create a new blank file somewhere and give it .udl for an extension. It should change to an icon with a table and a white page with 0s and 1s in the background.
Double-click on it to open the "Data Link Properties" dialog
On the Provider tab, choose "Microsoft OLEDB Provider for SQL Server"
On the Connection tab, fill in the remote server details and credentials
Click "Test Connection"
Where to start?
Try looking for the correct connection string here
You then need to find an example using the System.Data.SqlClient
By 'connect through the internet' do you mean connect from the internet to a SQL Server?
You need to open appropriate ports in the firewall and NAT them to your SQL Server.
To get you started, I would install a copy of SQL Server Express onto your local workstation and create an SQL Server instance with SQL Server Authentication. Also install SQL Server Management Studio which is a visual console through which you can manage your database and logins etc. They are available for free here:
http://www.microsoft.com/en-us/download/details.aspx?id=29062
Go into SQL Server Management Studio, create a database and a login username and password with sysadmin rights. Connect using the following code. The principles are similar to connect to an SQL Server database over the internet only there are more security issues to take into account.
Dim sConnectionString As String = "Server= MYCOMPUTERNAME\SQLEXPRESS;Database=DATABASE_NAME;User ID=USER_ID;Password=PASSWORD;Trusted_Connection=False;
Try
Dim mySqlConnection As New System.Data.SqlClient.SqlConnection()
mySqlConnection.ConnectionString = sConnectionString
mySqlConnection.Open()
MessageBox.Show("You have connected successfully to the SQL Server database.")
Catch SqlEx As SqlException
MessageBox.Show(SqlEx.Message & Constants.vbNewLine & Constants.vbNewLine & "You have NOT connected successfully to the SQL Server database.")
Catch ex As Exception
MessageBox.Show(ex.Message & Constants.vbNewLine & Constants.vbNewLine & "You have NOT connected successfully to the SQL Server database.")
End Try
I created an ODBC database on my local machine with driver SQL server Native client 10.0, which connects to a remote server, see
.
I am working on a project about customized ODBC to an inhouse database and want to Test how I can connect to a data source using ODBC.
The question is how can I connect to the local ODBC using sql server studio manager? I tried
but it returns an error:
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: Named
Pipes Provider, error: 40 - Could not open a connection to SQL Server)
Any idea?
Connect to your local server through SSMS then create a linked server to the ODBC connection.
Echoing #Brian Boyd...
It is possible to create an ODBC connection to a SQL server running locally.
If you start SSMS and point it to a local database engine the Server Name should be Computer_Name\SQLEXPRESS with Authentication set to Windows Auth (ie the logged-in user: you). Computer_Name is found in the System window (Windows Key + Break) and is not localhost, 127.0.0.1, etc.
So, to set up an ODBC connection by running %windir%\syswow64\odbcad32.exe
In the System DSN tab, click [Add...]
Select SQL Server in the drivers list, click [Finish]
Now add a Name and Description but most importantly set the Server to be Computer_Name\SQLEXPRESS (whatever was shown in SSMS)
Click [Next] and leave the authentication set to Windows NT
Click [Next] and tick the default database tickbox to reveal a list of databases locally (if yours is listed here the ODBC settings have already worked)
Click [Next], [Finish] then [Test Data Source...] then all should be well
To connect to a remote server you don't need a DSN. You can enter the server name in the Server name field of SQL Server Management Studio and select Windows authentication or Database authentication.
It is not possible to connect SSMS to an ODBC data source. The only way is to create a linked server in your local SQL server as #Brian Boyd described.
Instructions are:
https://community.sagecrm.com/partner_community/b/hints_tips_and_tricks/archive/2010/05/10/connecting-to-a-sage-mas-erp-90-database-as-a-linked-server-within-ms-sql-server-2008.aspx
... and sp_AddLinkedServer documentation from MS HERE
… and with search = “sp_addlinkedserver for SOTAMAS90“, even an example from 2005
https://blog.coryfoy.com/2005/06/lets-go-crazy-accessing-timberline-pervasive-data-from-a-sql-linked-server/
Let’s see what turn says …. And think I will / would get the same error adding a linked server through UI that I get TSQL
Based on above, I tried …
EXEC sp_addlinkedserver
#server = 'TimberlineTest',
#provider = 'SOTAMAS90', -- Original command #provider = MSDASQL',
#srvproduct = '', --- MAS 90 4.0 ODBC Driver Original is #srvproduct='Timberline Data',
#datasrc = 'DataTest'
I have a SQL Server 2008 on a server which goes out on the internet through a domain name computer.example.com, I want to develop a .net app on my PC and to connect to that database through SSMS - to create tables and so on...
And I still want a connection string which can be accessed from anywhere - I'm thinking at a http url or something like that - which will be consumed by the app.
What do I must to configure on the server so that I can connect via SSMS to the database (from my PC) and how do I get a connection string to that database?
you can use Sql Server Configuration Manager for this work. when you run this application, expand the SQL Server Network Configuration, after that you can see Protocols for sql server 2008. by click on it you can enable or disable TCP/IP.
your connection string can be like this :
connectionString="Database=DBName;Server = Server IP;Integrated Security=false;user id=sa; password=Pass;
I'm trying to make a connection to a SQL Server Express DB on localhost, but I get the following error message:
Microsoft OLE DB Provider for SQL Server (0x80004005)
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or
access denied.
The code I'm using is
Dim connection
Set connection = CreateObject("ADODB.connection")
connection.connectionString = "server=localhost;Provider=SQLOLEDB;Data Source=RiskManagement;Initial Catalog=RiskManagement;User ID=sa;Password=myPass;"
connection.Open()
Any ideas?
First thing to always check is that you have configured SQL Server to allow remote connections.
How to configure SQL Server 2005 to allow remote connections
For generic SQL Server Connectivity Troubleshooting consult the following Blog Post
I also faced same issue, when I investigated around the network connectvity then I come to know from application server (example Windows 10.10.10.10 or AppServer) is unable to connect database server (Like DBServer or 10.10.10.11). So once check whether it's pinging from the application server, where application is hosted or located.
I got this issue because ESET firewall was on.
I installed an update of a VB6 program. The new .exe had to be entered into the firewall