SQL Server linked server not working in ASP Classic - sql-server

I've created a linked server to an Excel spreedsheet. It's ok and working in SQL Server I can query excel file in query analyzer.
But when I'm trying to access this link server in my asp page:
Set pishbini = Server.CreateObject("ADODB.Recordset")
pishbini.ActiveConnection = MM_semmet_STRING
pishbini.Source = "SELECT * FROM OPENQUERY(SemnanmetWeekly, 'SELECT * FROM [DayPish$]')"
pishbini.CursorType = 0
pishbini.CursorLocation = 2
pishbini.LockType = 1
pishbini.Open()
SemnanmetWeekly is the name of linked server in SQL Server I'm getting this error in my asp page:
Microsoft OLE DB Provider for ODBC Drivers error '80040e14'
[Microsoft][ODBC SQL Server Driver][SQL Server]OLE DB provider
"Microsoft.Jet.OLEDB.4.0" for linked server "SemnanmetWeekly" returned
message "Cannot start your application. The workgroup information file
is missing or opened exclusively by another user.".
/Daypish.asp, line 15
IUSR (IIS user) has full access to excel file, I have played with all the different options in in my Link Server Options like impersonating or accessing excel file with administrator account, but error remained the same!
I prefer to not change the code, since I'm only doing administration stuff on this server. it has been working on an old server but since we moved it to new server it stopped working. anything I'm missing here?

Not related to permissions. I think you logged in to Sql Server with Windows Authentication, everything is okay, you're the boss. But, if the connection in ASP is SQL authenticated, you get this error. So, you should add a linked server login with a query similar to following.
Exec master..sp_addlinkedsrvlogin
#rmtsrvname = N'SemnanmetWeekly',
#useself = N'False',
#locallogin = N'sa', /* replace your own - same as sql server authenticated account */
#rmtuser = NULL,
#rmtpassword = NULL
Then you can connect to SemnanmetWeekly in your ASP application.

Related

SQL Server 2019 Polybase error - cant create External Data Source to SQL Server 2019

I am trying to setup an external data source in SQL Server 2019 to another database on the same server.
I am doing this to replicate the SQL Azure setup currently running in production.
I tried the following to set it up
I installed SQL Server 2019 Express
I installed Polybase
I enabled TCP/IP and made sure services were running
I then ran
USE master
CREATE MASTER KEY ENCRYPTION BY PASSWORD = 'xxxxxxxxxxxxxxxxxxx'
EXEC sp_configure #configname = 'polybase enabled', #configvalue = 1;
RECONFIGURE;
USE mydb
CREATE DATABASE SCOPED CREDENTIAL SqlServerCredentials
WITH IDENTITY = 'sa', SECRET = 'xxxxxxxx';
CREATE EXTERNAL DATA SOURCE SQLServerInstance
WITH ( LOCATION = 'sqlserver://.\sqlexpress',
PUSHDOWN = ON,
CREDENTIAL = SQLServerCredentials);
On the final CREATE EXTERNAL DATA SOURCE statement I get this error
OLE DB provider "MSOLEDBSQL" for linked server "(null)" returned message "Cannot generate SSPI context".
Msg -2146893042, Level 16, State 1, Line 0
SQL Server Network Interfaces: No credentials are available in the security package
I can't seem to figure out why I get this error

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

SQL server 2016 external data source - Incorrect syntax near 'external'

I have a SQL server 2016 with a DB running on it. The SQL server runs on a Windows server 2016 as a VM through Azure.
Within that DB I'd like to create an external data source that reference a DB on another server remote server.
I have created the necessary credentials.
CREATE EXTERNAL DATA SOURCE EXTERNALDS WITH
(TYPE = HADOOP,
LOCATION = N'***',
CREDENTIAL = Credentials,
DATABASE_NAME = N'***'
);
Executing this query returns the following error message;
Incorrect syntax near 'EXTERNAL'.

How can I connect to a local ODBC datasource

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'

Error "Microsoft SQL Native Client error '80040e37'"

After moving my database and web site for another server I got the error Microsoft SQL Native Client error '80040e37'.
The problem occurs in a query inside an asp file that do not have schema.tablename, only tablename. But I do not want to include "schema" in all queries right now.
All updates were installed and the default schema for my user is correct.
SQL Server is configure to mixed mode and to accept both windows authentication and sql server authentication.
Softwares: IIS 6, Sql Server 2005.
Solved. The problem was "Orphaned" logins. The solution was to run the stored procedure sp_help_revlogin, copy its results and run them in the new server.
EXEC [dbo].[sp_help_revlogin]
Example Result:
CREATE LOGIN [exampleLogin] WITH PASSWORD = 0x0100E634633EB1BF18E HASHED, SID = 0x840D462D26543B4FB71234B36137A131, DEFAULT_DATABASE = [yourDB], CHECK_POLICY = OFF, CHECK_EXPIRATION = OFF

Resources