How to access SQL Server through internet? - sql-server

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

Related

Database connection in ASP Classic

I got an ASP-Classic Page from 2001.
I upgraded/migrated the Database to an actual SQL Server Version (2016).
My problem is, when I try to connect to the database I always get an error message, that I cannot connect to the server because of the given user. I created a user on my SQL Server, this is the one I want to use for the connection but it doesn't work.
Here's the code:
Provider=sqloledb;Data Source=localhost\SQLEXPRESS;Initial Catalog=LV; User ID=lvsupervisor;Password=analogis;
The login credentials are correct. Maybe someone can help me here.
ASP Classic 3 itself works smoothly even with latest version of MS SQL (2019).
My problem is, when I try to connect to the database I always get an error message, that I cannot connect to the server because of the given user.
First of all verify that user itself able to login to MS SQL Server. Run MS SQL Management Studio and try to login to server by using user credential you have. Does it works? Could you see data in Tables?
migrated the Database to an actual SQL Server Version (2016)
Connection string: try different provider, for example Provider=SQLOLEDB.1
Delete your current DSN and create a new one using "SQL Server Authentication" instead of "Windows Authentication". Create a new user with admin/read/write permissions and nominate that account for the new DSN connection. Use a 64-bit DSN for default server or if you have enabled 32-bit applications for the site, then you must use a 32-bit DSN connection. Then you can use...
strConnection = "DSN=ExampleName;DRIVER={SQL Server};UID=ExampleUser;PWD=ExamplePass"
Set dbConnection = server.CreateObject("ADODB.Connection")
dbConnection.ConnectionString = strConnection
dbConnection.Open
SQLFunction = "SELECT ID FROM Example Where CExample.Key = '" & strInputCom & "' "
Set rsFunction = dbConnection.Execute(SQLFunction)
if not rsFunction.EOF then
strClientId = rsFunction("ID").value
else
strClientId = ""
end if
rsFunction.Close
Set rsFunction = Nothing

Connect from application to SQL Server (ONLY Theoretical!)

I don't know how to connect from a self-written application to a SQL Server. I have added an application role to the SQL Server already. Do I need a SQL Server login or only a database user? I know that after I'm connected I can run the procedure sp_setapprole to access the database as an application. How does this work in theory?
You need a connection string
(instructions on how to connect to the SQL Server: URL,PORT,USERNAME,PASSWORD) and a command to be Executed.
I'm sure there are a lot of instructions online for you, just give it a quick google search:
%Programming_Language & "SQL Connection String"

ODBC DSN Connection Error - SQL Server 2014 Express Classic ASP

Trying to connect a classic asp page to sql server express 2014 using a dsn.
I've created a new database (in sql server management studio) called warehouse, with a table called users. I've added a new login called user1 with a password and mapped it to the warehouse database
I've created an ODBC System DSN on the same machine, using sql server native client 11 driver called SQLServer2 with integrated windows authentication, and a default database warehouse. Testing the connection at this point works fine!
On the ASP page I'm using:-
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.Open "dsn=SQLServer2;uid=user1;pwd=xyz;"
Error:- Microsoft OLE DB Provider for ODBC Drivers error '80040e4d'
[Microsoft][SQL Server Native Client 11.0][SQL Server]Cannot open
database "warehouse" requested by the login. The login failed.
I'm pretty sure that its a permissions issue and that the connection string is OK otherwise but after hours and hours of trying different strings, different users, I can't seem to get the damn thing to connect
If Anyone can throw any ideas my way I'd be very grateful. Thanks!
The way you are describing the problem the DSN uses integrated security so your credentials might be ignored and the database is called using the application pool identity.
If you have no specific reason why you need to use a DSN I would recommend using a connection string like the following:
objConn.Open "Provider=sqloledb;Server=yourdbserver;uid=user1;pwd=xyz;Database=warehouse"
A look into your SQL server log might give you a hint as to which user is actually failing to connect to your database.
I think you should have done something like this
Set objConn = Server.CreateObject("ADODB.Connection")
objConn.ConnectionString "dsn=SQLServer2;uid=user1;pwd=xyz;"
objConn.open

Excel VBA connect to SQL Server Login Error

I am a beginner in Excel VBA and faced a problem: I can connect to remote SQL Server through Management Studio, but got error when connecting through Excel VBA.
Below is my connection string and the error code.
Const connection_string As String = "Provider=SQLOLEDB.1;Persist Security Info=True;Integrated Security=SSPI;Initial Catalog=RPGTFDB;Data Source=122.xxx.xxx.xxx;User ID=sa;Password=xxx"
Error is:
Run-time error (80004005): Login failed for user ". The user is not associated with a trusted SQL Server connection.
Is it not able to get the User ID?
However when I connect to local computer, like 127.0.0.1, the above connection string works.
Thanks a lot!
In your connection string you should not use
User ID=sa;Password=xxx
As the error seems to be indicating that only Windows Logins are enabled on the SQL Server and this connection string item is only for SQL Logins.
Do you have to punch in a login and password when connecting with management studio? If not then I suggest you have a database that authenticates a connection using your windows login.
If this is the case, then remove the User ID and Password bits and insert Trusted_Connection=Yes instead.
Finally, the connection string is created using UDL application.
Despite I still cannot find any difference between the string and the manual created one, it works!
Follow the instructions in this link:
http://social.technet.microsoft.com/wiki/contents/articles/1409.how-to-create-a-sql-connection-string-for-an-application-udl-file.aspx

CLASSIC ASP - SQL Server does not exist or access denied

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

Resources