SQL Server 2008 connecting to instance is not working - sql

I am trying to deploy my database on a customer server
I tried this:
select ##servername
and I got this
`INCONCERTSERVER`
Then I tried to create this stored procedure:
CREATE PROCEDURE [dbo].[getAgentStatues]
AS
BEGIN
SET NOCOUNT ON
EXECUTE sp_configure 'Show Advanced Options', 1
RECONFIGURE
EXECUTE sp_configure 'Ad Hoc Distributed Queries', 1
RECONFIGURE
SELECT UserName, LoggedState, InteractionId, InteractionType --<-- The columns required.
FROM
OPENROWSET('SQLNCLI'
,'Server=INCONCERTSERVER;Trusted_Connection=yes;database=MMProDat'
,'EXECUTE dbo.[SupGetAgentsWithInteractions]')
END
I got this error:
OLE DB provider "SQLNCLI10" for linked server "(null)" returned message "Login timeout expired".
OLE DB provider "SQLNCLI10" for linked server "(null)" returned message "A network-related or instance-specific error has occurred while establishing a connection to SQL Server. Server is not found or not accessible. Check if instance name is correct and if SQL Server is configured to allow remote connections. For more information see SQL Server Books Online.".
Msg 53, Level 16, State 1, Line 0
Named Pipes Provider: Could not open a connection to SQL Server [53].
Could you help me please?
I am already using a windows admistrator accound and an administrator on the database
I am working remotely using remote desk top

Try something like this....
CREATE PROCEDURE [dbo].[getAgentStatues]
AS
BEGIN
SET NOCOUNT ON;
SELECT UserName, LoggedState, InteractionId, InteractionType
FROM
OPENROWSET('SQLNCLI'
,'Server=INCONCERTSERVER;Trusted_Connection=yes;database=MMProDat'
,'SET FMTONLY OFF;SET NOCOUNT ON;EXECUTE dbo.[SupGetAgentsWithInteractions]')
END
Execute Proc
EXECUTE sp_configure 'Show Advanced Options', 1
GO
RECONFIGURE
GO
EXECUTE sp_configure 'Ad Hoc Distributed Queries', 1
GO
RECONFIGURE
GO
EXECUTE [dbo].[getAgentStatues]
GO

Related

Azure SQL Server "clr strict security" can this be changed

I'm trying to change the 'clr strict security' in Azure SQL Server, but not able, is this no more possible in Azure Managed SQL Server.
I've created a certificate first and then I tried to create a login for the certificate and thats failing as well, is this changed and can this be done in some other way.
CREATE LOGIN MIRRepoCertLogin FROM CERTIFICATE MIRRepoCert;
This is also failing with Keyword or statement option 'CERTIFICATE' is not supported in this version of SQL Server
My intention was to run the below commands in Azure SQL Server. Any advise.
EXEC sp_configure 'show advanced options', 1;
RECONFIGURE with override;
EXEC sp_configure 'clr strict security', 0;
RECONFIGURE with override;
EXEC sp_configure 'show advanced options', 0;
RECONFIGURE with override;
Important
As far as we know, the sp_configure and the SQL Statemenst of Certificate are not supported by Azure SQL Server.
When I try to execute the CREATE LOGIN xxx FROM CERTIFICATE xxx command. It shows the error is not supported in Azure Managed SQL Server.
When I try to execute the EXEC sp_configure command. It also shows is not supported

How to access Database from other computer using sql query in sql server

I am using a SQL database residing on my local computer. I want to access a table from a database residing on another computer using SQL query.
I have been able to connect the remote database with my database and all its tables are shown in Enterprise manager on my local machine. I have added remote SQL Server in my local SQL Server.
When I use select statement in my local SQL server it gives the message database does not exist or access denied.
Any help in this would highly be appreciated.
EDITED
Select * from [ServerName].DatabaseName.dbo.tableName
Use OPENROWSET
Example
SELECT t.version FROM
OPENROWSET('SQLNCLI', 'server=Myserver;UID=xxxx;pwd=yyyy',
'select ##version version') t
Note:
SQLNCLI is the name of installed OLE DB provider
Datasource: {server=Myserver;UID=xxx;pwd=yyy}
You have to enable OPENROWSET by executing the following script:
sp_configure 'show advanced options', 1
reconfigure
go
sp_configure 'Ad Hoc Distributed Queries', 1
reconfigure
OPENROWSET is like connecting to a linked server

SQL Linked server - Remote access error when executing SP

I've set up a linked server between an instance on SQL 2012 and SQL 2008R2 but
I keep getting the below error when trying to execute a stored procedure on a remote server:
Msg 7201, Level 17, State 4, Line 1
Could not execute procedure on remote server 'TEST' because SQL Server is not configured for remote access. Ask your system administrator to reconfigure SQL Server to allow remote access.
I've checked on both servers and they're configured to allow remote connections. The login that I've used has sysadmin access on the remote server and I can see all the databases when I expand 'Catalogs' within the linked server. When I test the connection this also says it's connected successfully. The SQL Service account also has SA on both instances for what it's worth
The odd thing is when I run a simple select query on one of the tables within the database it shows a result but it doesn't seem to like the SP.
Select * from Linkserver.database.dbo.table
The above works fine but this SP doesn't:
EXECUTE Linkedserver.database.[dbo].[SP] ....
Any recommendation would be appreciated.
Despite being an old thread, forget about enabling remote access (and restart service) on remote server and try:
EXECUTE (N'database.[dbo].[SP]') AT Linkedserver
If you want to run SPs from Server B, then make Server B as the linked server in server A.
Run the script below in Server A, not B:
EXEC sp_configure 'remote access', 1; RECONFIGURE;
Then restart SQL Service in A.
Done.
Please first check your server properties if remote connections is allowed (related picture below). IF yes, use: exec nameofyourSP 'remote access', 1 reconfigure and try again.
First Run:
EXEC sp_configure 'remote access', '1';
RECONFIGURE;
You now need to restart MSSQLSERVER in order for the sp_configure command to take effect.
Once you restart it, run sp_configure again and notice that the run_value is 1 now. That's what you want.

SQL Query to import data from 50 Access ACCDB databases

I am new to SQL, so please forgive my ignorance. I downloaded the free version of SQL Server Express Edition 2014 and have a 32 bit machine. I'm using Microsoft SQL Server Mgmt Studio. I am trying to setup a process to either link to or import 50 Access tables that are in 50 individual Microsoft Access 2013 databases (updated weekly) into SQL. I currently do this in an Access 2013 db but I am trying to replace the process. I downloaded the free version of SQL Server Express Edition 2014 and have a 32 bit machine. I'm using Microsoft SQL Server Mgmt Studio on my PC. Below is the code I put together. however, this is the result in the message window:
Configuration option 'show advanced options' changed from 1 to 1. Run the RECONFIGURE statement to install.
Configuration option 'Ad Hoc Distributed Queries' changed from 1 to 1. Run the RECONFIGURE statement to install.
Msg 7403, Level 16, State 1, Line 8
The OLE DB provider "Microsoft.Jet.OLEDB.12.0" has not been registered.
I am a newbie so I would greatly appreciate no assumptions in knowledge. Thank you.
sp_configure 'show advanced options', 1;
RECONFIGURE WITH OVERRIDE;
GO
sp_configure 'Ad Hoc Distributed Queries', 1;
RECONFIGURE WITH OVERRIDE;
GO
INSERT INTO TEST2.dbo.MyTest
SELECT * FROM OPENDATASOURCE(
'Microsoft.Jet.OLEDB.12.0',
'Data Source="D:\data\EXCEPT2.accdb"')...Testtbl;
GO
Turns out I had to run the below code to get the sql to work. I also had changed 'Microsoft.Jet.OLEDB.12.0', to 'Microsoft.Jet.ACE.12.0',
USE [master]
GO
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

Cannot read Excel file from SQL Server with multiple versions of SQL Server

EXEC sp_configure 'show advanced options', 1
RECONFIGURE
GO
EXEC sp_configure 'ad hoc distributed queries', 1
RECONFIGURE
GO
USE [master]
GO
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
Reading Excel
DECLARE #SQLconnect VARCHAR(8000)
SET #SQLconnect = 'SELECT * FROM OPENROWSET(''Microsoft.ACE.OLEDB.12.0'',
''Excel 8.0;Database=D:\WAGES.xlsx;'',
''SELECT * FROM [Sheet2$]'')'
EXEC (#SQLconnect)
Exception
Msg 7399, Level 16, State 1, Line 1
The OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)" reported an error. The provider reported an unexpected catastrophic failure.
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider "Microsoft.ACE.OLEDB.12.0" for linked server "(null)".
Sometimes it gives error sometimes it goes in infinite loop of execution.
NOTE: I am getting this error after installing SQL Server 2008 R2 over SQL Server 2012.
OS: Windows 7 32-bit
SQL Server 2008 R2 and SQL Server 2012 installed
The SQL Server Error Message if a user have no rights for SQL Server TEMP directory:
OLE DB provider "Microsoft.Jet.OLEDB.4.0" for linked server "(null)"
returned message "Unspecified error".
Msg 7303, Level 16, State 1, Line 1
Cannot initialize the data source object of OLE DB provider
"Microsoft.Jet.OLEDB.4.0" for linked server "(null)".
Grant rigths to TEMP directory
(i.) This step is required only for 32-bit SQL Server with any OLE DB provider
The main problem is that an OLE DB provider creates a temporary file during the query in the SQL Server temp directory using credentials of a user who run the query.
The default directory for SQL Server is a default directory for SQL Server service account.
If SQL Server is run under Network Service account the temp directory is like:
C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp
If SQL Server is run under Local Service account the temp directory is like:
C:\Windows\ServiceProfiles\LocalService\AppData\Local\Temp
Microsoft recommends two ways for the solution:
A change of SQL Server TEMP directory and a grant of full rights for all users to this directory.
Grant of read/write rights to the current SQL Server TEMP directory.
See details: PRB: "Unspecified error" Error 7399 Using OPENROWSET Against Jet Database
Usually only few accounts are used for import operations. So we can just add rights for these accounts.
For example, icacls utility can be used for the rights setup:
icacls C:\Windows\ServiceProfiles\NetworkService\AppData\Local\Temp /grant vs:(R,W)
For more information follow this Link
Try these settings
Open SQL Server Configuration Manager.
Select the SQL Server Services folder in the left pane.
Right-click the SQL Server (MSSQLSERVER) service in the right pane.
Click Properties.
Click the Advanced tab in the properties dialog that pops up.
Add “-g512;” to the front of the value for parameter “Startup Parameters”.
Click OK.