ODBC DSN Connection Error - SQL Server 2014 Express Classic ASP - sql-server

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

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

Can't connect to Visual Studio 2015 SQL DB using Excel?

!
I've tried using ADODB connection string and also in the Excel Data Connection Wizard.
I'm getting this error:
[DBNETLIB][ConnectionOpen(Connect()).]SQL Server does not exist or access is denied.
I can see the server created in Visual Studio with its databases fine, no worries, in SQL Server but not connect in Excel. I can connect in Excel to databases created in SQL Server but not those created in VS (2015).
It's seems like a server issue rather than database one but here's the connection string's anyway:
This works fine for database's created in SQL Server:
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=DESKTOP-ODUI05F\MSSQL2012;Initial Catalog=MyDatabase
but the same string generates the above error when connecting to the server/database created in VS.
Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=True;Data Source=(LocalDB)\MSSQLLocalDB;Initial Catalog=aspnet-Widly-20160823125202
The server name is: (LocalDB)\MSSQLLocalDB.
The database is generated in VS using EF.
Please help - driving me nuts.
Thank you, Simon
Solved!
Followed the solution linked below.
Even though it's an MSSQL Server DB you're trying to connect to, using Excel Data Connection Wizard you have to ignore SQL Database connection option and choose "Other/Advanced" instead. I recorded it in a macro which produced all the vital parts for the connection string as follows:
How to connect to localDB in Excel
Provider=SQLNCLI11;
Integrated Security=SSPI;
Persist Security Info=False;
Data Source=(LocalDB)\MSSQLLocalDB;
Initial Catalog=aspnet-PTL-20160827031609
Besides doing the dishes this is my biggest and only achievement today! :)

How to access SQL Server through internet?

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

Classic Asp Connection String to SQL Server 2012 with Windows Authentication on Windows 8

I'm want to migrate a number of MS Access 2007 Databases to SQL Server 2012 locally but before I do I would like to set up a generic connection string that works, I will the have to get them all up and running on the production server too.
This is a sample of the string I have to the .mdb file:
conditions_report = "Driver={Microsoft Access Driver (*.mdb)};DBQ=" + Server.MapPath("_private/conditions_report.mdb")
set conn = Server.CreateObject("ADODB.Connection")
conn.Mode = 3
conn.Open conditions_report
And this is about as far as I've come with creating something for the .mdf:
conditions_report = "Provider=SQLNCLI11;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=conditions_report;Data Source=XXX"
set conn = Server.CreateObject("ADODB.Connection")
conn.Mode = 3
conn.Open conditions_report
I only work in MVC these days and have never connected Classic Asp to SQL Server and due to time frames migrating from Classic Asp to MVC is not an option at the moment but this would be a at least a step in the right direction.
Edit
Another problem I'm having is I'm not sure what the error messages are telling me. I'm not sure if they are telling me my server is setup incorrectly, it's a permissions problem, a TCP IP issue, if it's not finding the server or finding the server and not the database and my connection string is just wrong! Some of the errors if have been getting are here:
[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied.
Named Pipes Provider: Could not open a connection to SQL Server [53].
Cannot open database "conditions_report" requested by the login. The login failed.
TCP Provider: A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.
Any help would be greatly appreciated.
I think SQLNCLI11 is the preferred driver for SQL Server 2012
http://www.connectionstrings.com/sql-server-native-client-11-0-oledb-provider/

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