Sql management Studio cosmos linkedServer - sql-server

I trying to create a linkedServer over sql management studio and a cosmos db.
I already created the system data source and the test is fine:
But after create the linkedServer when i trying to open this error appears :
I'm creating the linke server with the following command :
USE [master]
GO
EXEC master.dbo.sp_addlinkedserver #server = N'DEMOCOSMOS', #srvproduct=N'', #provider=N'MSDASQL', #datasrc=N'CosmosDev'
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'DEMOCOSMOS', #useself=N'False', #locallogin=NULL, #rmtuser=NULL, #rmtpassword=NULL
GO

Related

Error on Loading Assembly in While Calling CLR Command in SQL Server

I'm receiving an error when trying to run a CLR object from SQL Server:
An error occurred in the Microsoft .NET Framework while trying to load assembly id 65538...
Do I need to enable some SQL Server setting, or is it a bug?
First, you need to enable CLR execution by running this:
EXEC sp_configure 'clr enabled';
EXEC sp_configure 'clr enabled' , '1';
RECONFIGURE;
then change the owner by running this:
USE master
GO
ALTER DATABASE [database_name] SET TRUSTWORTHY ON
USE [database_name]
GO
EXEC sp_changedbowner 'sa'

sp_addlinkedserver is linking to local server not remote

I am trying to link a remote server using the following commands:
EXEC sp_addlinkedserver
#server='REMOTESERVER', #srvproduct='',#provider='SQLNCLI'
EXEC sp_addlinkedsrvlogin
#useself='FALSE', #rmtsrvname='REMOTESERVER',
#rmtuser='user', #rmtpassword='pwd'
sp_testlinkedserver REMOTESERVER;
Where REMOTESERVER is the value returned on the remote server when I execute SELECT ##Servername
All command execute successfully. However when I view the catalog for my 'linked' server (in SSMS) it is listing the tables in the local server, not the remote. Equally if I run a query
SELECT * FROM [REMOTESERVER].localdb.dbo.localtablename;
It will return a results set from the local server.
Note I have confirmed that remote access is enabled as recommended in https://blogs.msdn.microsoft.com/walzenbach/2010/04/14/how-to-enable-remote-connections-in-sql-server-2008/
Any ideas? Thanks in advance.
Solved this by adding the remote IP address to the sp_addlinkedserver command:
sp_addlinkedserver
#server = N'REMOTESERVER',
#srvproduct=N'SQLNCLI',
#provider=N'SQLNCLI',
#datasrc=N'99.99.99.99'

Export SQL QueryResult to Excell file on Server without installing Office

I want write result rows of a query to a excell file:
INSERT into OPENROWSET('Microsoft.ACE.OLEDB.12.0',
'Excel 12.0;Database=C:\temp\testing.xlsx;',
'SELECT Id,CompanyName FROM [Sheet1$]')
select Id,CompanyName from tbl_Company
But When Running This query following error occurs :
Msg 7302, Level 16, State 1, Line 3
Cannot create an instance of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
What is done before running this code :
1 - I installed "2007 Office System Driver: Data Connectivity Components"
2 - Executed Configuration Script for using excell :
sp_configure 'show advanced options', 1;
GO
RECONFIGURE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
GO
RECONFIGURE;
GO
3 - Change Login Account for SQL Server Service to local account
4 - Added Full Access permission on Excell file folder to local account
5 - Restarted SQL Service
But my problem remains
Server : Windows Server 2008
MS Office not installed on server
SQL Server 2014 64bit SP1
I had a mistake :
I should run this configuration script
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'AllowInProcess', 1
GO
EXEC master.dbo.sp_MSset_oledb_prop N'Microsoft.ACE.OLEDB.12.0', N'DynamicParameters', 1
GO
also you should be sure to install 64bit version of Access Database Engine (if your sql server is 64bit).

Create Database login in code

I have an application that creates and uses its own SQL Server Express database. It worked just fine using SQL Server 2008 Express on Windows 7, but I need to get it to work with SQL Server 2014 Express on Windows 10, and I'm getting an error.
I start with an admin connection string:
connectionString="Data Source=.\SQLEXPRESS2014;Initial Catalog=master;Integrated Security=SSPI"
Then with that connection I create the database by executing:
CREATE DATABASE mobile
ON
( NAME = mobile_dat,
FILENAME = '...\path\mydb.mdf',
FILEGROWTH = 5MB )
LOG ON
( NAME = 'mobile_log',
FILENAME = '...\path\mydb.ldf',
FILEGROWTH = 5MB );
And then I create a user:
CREATE LOGIN xxx WITH PASSWORD = 'xxx', CHECK_POLICY = OFF;
USE mobile
EXEC sp_adduser 'xxx', 'xxx';
EXEC sp_addrolemember 'db_owner', 'xxx';
EXEC sp_addrolemember 'db_accessadmin', 'xxx';
EXEC sp_addrolemember 'db_securityadmin', 'xxx';
EXEC sp_addrolemember 'db_ddladmin', 'xxx';
EXEC sp_addrolemember 'db_backupoperator', 'xxx';
EXEC sp_addrolemember 'db_datareader', 'xxx';
EXEC sp_addrolemember 'db_datawriter', 'xxx';
At which point I disconnect and connect as the new user:
connectionString="Data Source=.\SQLEXPRESS2014;Initial Catalog=mobile;User Id=xxx;Password=xxx;"
This worked fine with SQL Server 2008 Express on Windows 7, but on with SQL Server 2014 Express on Windows 10 I'm getting an error:
Login failed for user 'xxx'.
Any ideas as to what I'm missing?
Do you have mixed mode authentication enabled in the SQL Server Express 2014 installation? It's disabled by default IIRC.
If it is enabled use Microsoft Management Studio to try and login and see what error it gives you.

Connect a protected access database to sql server

I Have a password-protected access database (.mdb) and sql server 2008 running in windows server 2008 R2 x64.
I installed "Microsost Access Database Engine" and I want to create a linked server to access, but I get this error:
"Cannot start your application. The workgroup information file is missing or opened exclusively by another user".
there is not any *.mdw file on my server.
I'm able to add a linked server to an unprotected database, but not to a protected database.
How can I add a mdw file without install MS access?
or is there any oher way to add a linked server?
USE THIS:
EXEC master.dbo.sp_addlinkedserver #server = N'Access', #srvproduct=N'Access', #provider=N'Microsoft.Jet.OLEDB.4.0',
#datasrc=N'C:\Program Files\ZKTime5.0\att2000.mdb'
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'Access',#useself=N'False',#locallogin=NULL,#rmtuser=N'Admin',#rmtpassword=''
this works for me.
I am okay with the SQL script for creating linked servers:
////////////////Create linked server with no password access file
EXEC master.dbo.sp_addlinkedserver #server = N'linkedserver', #srvproduct=N'Smarthr', #provider=N'Microsoft.ACE.OLEDB.12.0', #datasrc=N'dbpath\file.mdb'
EXEC master.dbo.sp_addlinkedsrvlogin #rmtsrvname=N'LINKEDSVR',#useself=N'False',#locallogin=NULL,#rmtuser=NULL,#rmtpassword=NULL
//////////////////////////Create linked server with access password file
exec sp_addlinkedserver
#server = 'LinkServer',
#provider = 'Microsoft.ACE.OLEDB.12.0',
#srvproduct = 'Access4',
#datasrc = 'dbpath\filename.mdb',
#provstr = ';PWD=yourpassword'
exec sp_addlinkedsrvlogin
#rmtsrvname = 'LinkServer',
#useself = 'FALSE',
#locallogin = null,
#rmtuser = 'Admin',
#rmtpassword = null

Resources