What connection string and or OLEDB/ODBC drivers when moving "classic ASP/ADO" app from SQL Server 2008 to SQL Server 2017? - sql-server

My "classic ASP" application is on Windows Server 2003 and uses ADO to connect to a SQL Server 2008 database.
The database server is being upgraded from a changing and will be running SQL Server 2017.
I am trying to prove that the old application can still work, connecting to this newer version of SQL Server.
I have so far not had success in making a connection to a SQL Server 2017 installation from the old WS2003 machine.
I am not sure what OLEDB or ODBC providers or drivers I need to install to get this to work, and ultimately, what the Connection String will need to be.
I have created a small demo program to make the connection using the same code as the real application will. Essentially, all I am doing here is providing a connection string and attempting to connect. This is VB6 using ADO:
Private Sub btnConnect_Click()
Dim theConnection As New ADODB.Connection
theConnection.ConnectionString = Text1.Text
theConnection.Open ConnectString
If theConnection.State = 1 Then
MsgBox ("connected ")
Else
MsgBox ("failed to connect ")
End If
End Sub
I can get this program to run on the new server - the one with SQL Server 2017, and it connects successfully.
This connection string works :
Driver={SQL Server Native Client 11.0};Server=192.168.0.23;Database=TestDB;Uid=user1;Pwd=xxx;
This also works :
Driver={SQL Server};Server=192.168.0.23;Database=TestDB;Uid=user1;Pwd=xxx;
This one is the exact format that the existing code uses to connect.
Now, I understand that for ADO, I have not specified Provider, so I think it defaults to MSDASQL, Microsoft's OLEDB provider for ODBC.
So, to get this to connect from the WS2003 application server, is where I have problems. Is this going to be possible?
I have tried these connection strings with these results :
Driver={SQL Server};Server=<IP address of SQL2008 server>;Database=yyy;Uid=xxx;Pwd=xxx;
This WORKS - and this is the existing SQL2008 database.
Driver={SQL Server};Server=<IP address of SQL2017 server>;Database=TestDB;Uid=user1;Pwd=xxx;
This takes approx 20-30 seconds to fail with this message :
[ODBC SQL SERVER DRIVER]SQL Server does not exist or access denied
Is the "old" {SQL Server} driver going to be able to connect to to SQL2017?
Driver={SQL Server Native Client 11.0};Server=192.168.0.23;Database=TestDB;Uid=user1;Pwd=user1;
This fails immediately with the message :
[ODBC Driver Manager]Data Source Name not found and no default driver
specified
Does this mean that the {SQL Server Native Client 11.0} ODBC driver is not installed on the WS2003 machine? Can it be installed?
I have tried looking at the various ODBC driver installations from Microsoft here : https://learn.microsoft.com/en-us/sql/connect/odbc/download-odbc-driver-for-sql-server?view=sql-server-2017
However, I'm not sure if I need to be doing this or if they are compatible with WS2003.
Microsoft ODBC Driver 17 for SQL Server : requires at least Windows Server 2008 R2. Same for Microsoft ODBC Driver 13 and 11. I did get the version 11 to install, event though it probably is not supported. I did use this to successfully create a new ODBC data source to the old SQL2008 database, but not to the SQL2017 database.
What do I need to do to resolve this?

ADO doesn't use "Drivers" that's ODBC terminology. It uses OleDb "Providers". There are three OleDb providers for SQL Sever (in addition to MSDASQL, the OleDb Provider for ODBC drivers which shouldn't be necessary for SQL Server, since it has native OleDb providers).
The old, SQLOLEDB provider has been included in Windows since Windows Server 2003, and it's probably the right one to connect from your old server. The current one is MSOLEDBSQL, and is available here, and should be used whenever possible instead of the old SQLOLEDB or the newer, but deprecated SQLNCLI provider.
Here's a VbScript that you can use to test connections from any Windows computer.
Wscript.Echo "SQLOLEDB"
set theConnection = createobject("ADODB.Connection")
theConnection.ConnectionString = "Provider=SQLOLEDB;Data Source=localhost;Integrated Security=SSPI"
theConnection.Open ConnectString
Wscript.Echo "SQLNCLI"
set theConnection = createobject("ADODB.Connection")
theConnection.ConnectionString = "Provider=SQLNCLI;Data Source=localhost;Integrated Security=SSPI"
theConnection.Open ConnectString
Wscript.Echo "MSOLEDBSQL"
set theConnection = createobject("ADODB.Connection")
theConnection.ConnectionString = "Provider=MSOLEDBSQL;Data Source=localhost;Integrated Security=SSPI"
theConnection.Open ConnectString
Save it to a .vbs file and run it with the command:
c:\test> cscript test.vbs

Related

Windows10 SQL Server 2017 Classic ASP connection - SSL Security Error

I'm building up a new machine with Windows10 and SQL Server 2017 and am having a hard time getting my legacy ASP applications to connect properly.
The Connection string looks like this:
"driver={SQL Server};uid=USERNAME;pwd=PASSWORD;server=LocalServer;Database=LocalDB;"
I'm able to connect with a connection string like this:
"Provider=SQLNCLI11;Server=LocalServer;Database=LocalDB;Integrated Security=SSPI;DataTypeCompatibility=80;MARS Connection=True;"
... but that causes a bunch of errors with the way the existing code and how it interacts with Stored Procs so I'm trying to get the first connection string to work.
The error I get with that string is this:
Microsoft OLE DB Provider for ODBC Drivers error '80004005'
[Microsoft][ODBC SQL Server Driver][Shared Memory]SSL Security error
/Codeshare/ServerSide/conx_current.asp, line 8
That code looks like this:
dim sqlconn
set sqlconn = server.CreateObject("ADODB.CONNECTION")
dim cn : cn = getConx("current")
sqlconn.open cn
... where getConx("current") just returns the Connection String from above
If it helps, I get the same error message if I try to create an ODBC connection using the SQL Server or SQL Server Native Client 11.0 drivers.
TIA
Sounds like the SQL Sever has been hardened to only allow the more secure protocols like TLS 1.2 and associated strong ciphers. The problem is that the older providers don't support these more up to date protocols. SQLNCLI11 does but as you have discovered how ADO behaves differently which then breaks ASP sites.
For the most part I found that adding SET NOCOUNT ON to the top of SPs and SQL batches restores 90% of the functionality. Then its a case of hunting the other issues.
The alternative would be to wind back the server hardening by re-enabling older protocols like SSL3 and re-enabling the lest secure ciphers
Search "TLS 1.2 and SQLNCLI11"

empty recordset values - sql server 2017

I always used this connection string in my codes to connect to sql server:
"Driver={SQL Server};Server=SERVER_ADDRESS;Database=DBNAME;User Id=MYUSER;Password=******;"
In a new website when I deployed the project on the real server I noticed that I have to use a new connection string due to sql server version:
"Driver={ODBC Driver 17 for SQL Server};Server=SERVER_ADDRESS;Database=DBNAME;User Id=MYUSER;Password=*****;"
The connection works fine and the website is working without error but all values in recordsets are empty! I have 5 menus as there are 5 records in database but all menus are displaying empty text! In fact all texts are empty however there are text records in database (when I check with SSMS). Do I need to add something new to my codes or to the connection string?
This is how I get data from database:
Set objcon = Server.CreateObject("ADODB.Connection")
objcon.connectionString="Driver={ODBC Driver 17 for SQL Server};Server=SERVER_ADDRESS;Database=DBNAME;User Id=MYUSER;Password=*****;"
objcon.Open
Set rs= Server.CreateObject("ADODB.RecordSet")
rs.CursorType = 2
rs.open "select * from menu",objcon
while not rs.eof
Response.Write rs("title") 'I get 5 empty texts here as I have 5 record in database
rs.movenext
wend
rs.close
It is best to use OLE DB with ADO classic. ADO is natively a COM-based API and uses the MSDASQL (Microsoft OLE DB Provider for ODBC drivers) on top of the ODBC call-level interface, adding an addition API layer.
Windows ships with SQLOLEDB (Microsoft OLE DB Provider for SQL Server) for backwards compatibility. This driver is intended to be used only for legacy application APIs like ADO classic. ADO classic is forever stuck in the SQL 2000 world and lacks data type mappings for newer SQL Server data types introduced in the last 20 years. With It is a good practice to also specify the DataTypeCompatibility=80 connection string keyword to avoid surprises.
You could also use the MSOLEDBSQL driver (Microsoft OLE DB Driver for SQL Server), which is a separate download as are all modern SQL Server drivers. However, there are behavior differences between SQLOLEDB and MSOLEDBSQL that may require additional application testing.

What is the connection string to connect to local db file (.mdf)

I use the following connection string to connect to database in the sqlserver instance SQLEXPRESS:
QString connStr = "DRIVER={SQL SERVER};SERVER=%1;DATABASE=%2;";
But I want now to connect to SQL Server database file (.mdf) and I already installed Microsoft SQL Server 2016 LocalDB. What connection string should I use?
I tried the following connection string:
QString connStr = "DRIVER={SQL SERVER};SERVER=%1;AttachDbFileName=%2;"
db.setDatabaseName(connStr.arg("(LocalDB)\\v11.0",dbFilename));
And I also tried a different server:
db.setDatabaseName(connStr.arg("(LocalDB)\\MSSQLLocalDB",dbFilename));
But none of them works and throw the same error:
"[Microsoft][ODBC SQL Server Driver][DBNETLIB]SQL Server does not
exist or access denied. [Microsoft][ODBC SQL Server
Driver][DBNETLIB]ConnectionOpen (Connect()). QODBC3: Unable to
connect"
After some researches I found the solution:
1- Ensure that Microsoft SQL Server 2016 LocalDB is installed.
2- Change the 'Driver' in the connection string to:
DRIVER={ODBC Driver 13 for SQL Server}
3- Ensure the attribute 'AttachDbFileName' points to the correct database file path, especially you need to pay attention to the path separator whereas QT use "/" but in Windows you have to use "\" ("\\") <-- (This is was my main problem).
To get rid of this problem use QDir::toNativeSeparators(dbFilename).
So and after those changes the connection string will be like this:
QString connStr = "DRIVER={ODBC Driver 13 for SQL Server};SERVER=%1;AttachDbFilename=%2;Integrated Security=true;";
db.setDatabaseName(connStr.arg("(localdb)\\MSSQLLocalDB").arg(dbFilename));
Thanks.

Running a Classic ASP Application on 32-Bit Windows Seven With IIS 7.5

I recently upgraded my computer from XP to Windows Seven. I was using IIS 6.0 but I am now on IIS 7.5. When I was on my XP machine I was able to get my Classic ASP pages running and viewable. I am working being ableto run a Classic ASP page from my local drive. I am using SQL Server 2005. I set up IIS 7.5 with an application pool with .NET Framework Version 2.0. When I try to run the page I get the error: "Microsoft OLE DB Provider for ODBC Drivers error '80004005' [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified". My code looks like this:
randomConnection = "Provider=SQLOLEDB;Data Source=server\instance;Initial Catalog=myDataBase;User Id=MyFakeUserID;Password=MyFakePassword;"
Set someRS = Server.CreateObject("ADODB.RecordSet")
mySQLStatement = "SELECT DISTINCT CarInfo.CarMake, CarInfo.CarColor FROM CarInfo"
someRS.Open mySQLStatement, randomConnection
The code errors out on the last line. My code has a lot more that it does after all this. All of the code worked fine with IIS 6.0. The only changes are I switched to Windows Seven 32-bit and IIS 7.5. Is there something special that needs down since I have IIS 7.5? I have created test ASP pages in the root directory without any database logic and the page rendered just fine.
Your connection string is using the wrong provider - SQLOLEDB is a data provider for SQL Server 2000 or SQL Server 7. You should be using SQLNCLI (or SQLNCLI10) according to SQL Server 2005 connection strings.
Try this...
Provider=SQLNCLI;Data Source=server\instance;Initial Catalog=myDataBase;User Id=MyFakeUserID;Password=MyFakePassword;
You are also trying to open the connection using mySQLStatement as the connection string. You need to revisit the documentation on how to connect and request data from ADODB.
If you change the way you connect to the server does it work or give you a different error? I get different errors between using your version above and the version we use (the error I get with the below is because I don't have an instance called server\instance):
Set someRS = Server.CreateObject ("ADODB.Command")
someRS.ActiveConnection = "Provider=SQLOLEDB;Data Source=server\instance;Initial Catalog=myDataBase;User Id=MyFakeUserID;Password=MyFakePassword;"
someRS.CommandText = "SELECT DISTINCT CarInfo.CarMake, CarInfo.CarColor FROM CarInfo"
someRS.Prepared = true
Set someRSResults = someRS.Execute
Also, we use SQLOLEDB which has worked with SQL Server 2000, 2005 and 2008. Maybe we need to update it to the later one, but it should work.

Access Visual Studio 2008 server-based database from VB 6 project

Is it possible to access a Visual Studio 2008-created server-based database from a VB-6 application? If not, what is the best way to share a database between a VB-6 application and a C# application?
If you are referring to the SQL Server Express database that comes with Visual Studio 2008, you can access that with plain old ADO.
The connection strings for doing this are at http://connectionstrings.com/sql-server-2005. The most appropriate one is probably this one:
Driver={SQL Native Client};Server=myServerAddress;Database=myDataBase;
Uid=myUsername;Pwd=myPassword;
For SQL Server Express (which is what comes with VS2008), don't miss the server name syntax Servername\SQLEXPRESS where you substitute Servername with the name of the computer where the SQL Server 2005 Express installation resides.
The reference for programming against a SQL Server database using ADO is here:
http://msdn.microsoft.com/en-us/library/aa905875(SQL.80).aspx
Example for connecting to the SQL Server database is below (untested). Note that this one uses SQL Server authentication rather than Windows Authentication. Check your connection strings on http://www.connectionstrings.com. If SQL Native Client doesn't work, try one of the others.
' Initialize variables.
Dim cn As New ADODB.Connection
Dim connectionString As String
' Specify the OLE DB provider.
cn.Provider = "{SQL Native Client}"
' Specify connection string on Open method.
connectionString = Server=myMachineName\SQLEXPRESS;Database=myDataBase; _
Uid=myUsername;Pwd=myPassword;
cn.Open connectionString
I just added a "Service-based database" to a project. I go the following in my app.config, in the configuratonStrings element:
<add name="SerializeToSql.Properties.Settings.Database1ConnectionString"
connectionString="Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\Database1.mdf;Integrated Security=True;User Instance=True"
providerName="System.Data.SqlClient" />
I don't know if ADO has user instance support. if it does, then you may be able to create
an equivalent connection string for ADO to use. Otherwise, you'll need to just create a "normal" database in SQL Server Express. You should be able to use that from ADO.
In order for other machines to see your SQL Express instance, you need to make sure it allows remote connections, the SQL Browser service is turned on, and is allowed through the firewall.
Fire up the SQL Server 2005 Surface Area Configuration tool: All Programs->Microsoft SQL Server 2005->Configuration Tools->SQL Server Surface Area Configuration.
Click Surface Area Configuration for Services and Connections
Click the 'Remote Connections' node and select 'Local and remote connections'. If you want to refer to the server as ServerName\MSSQLSERVER, you'll have to user named pips or TCP/IP and named pipes.
Click the SQL Server Browser node. Change the Startup type to Automatic and start the service.
For the firewall, make sure you make an exception for the SQL Server program (C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\Binn\sqlservr.exe) and for the SQL Server Browser program (c:\Program Files\Microsoft SQL Server\90\Shared\sqlbrowser.exe)

Resources