YetAnotherForum
Welcome Guest Search | Active Topics | Log In | Register

OLEDB ERROR Options · View
blitzclipse
#1 Posted : Tuesday, February 08, 2011 3:30:29 AM
Rank: Member
Groups: Member

Joined: 1/15/2010
Posts: 13
Location: us
I am trying to execute a stored procedure from vba using integrated security. I can run the stored procedure form the sql management studio under the same user account that I am using in vba. I get the following error.

Run-Time error '-2147217900 (80040e14)':

OLE DB provider "PIOLEDB" for linked server "PILINK" returned message "[PI SDK] Unable to open a session on a server. Verify the local pinetmgr service and the remote PI system are running. LQRES020".


here is the vba:

Private Sub connect_to_sql()

'*****************************************************************************************************************
' Execute SQL Stored Procedure to update production calculation
'*****************************************************************************************************************
' Create a connection object.
Dim rstStringVal As String
Dim cn As ADODB.Connection
Set cn = New ADODB.Connection

Dim cmd As ADODB.Command

' Provide the connection string.
Dim strConn2 As String

'Use the SQL Server OLE DB Provider.
strConn2 = "PROVIDER=SQLOLEDB;"



'Connect to the Pubs database on the local server.
strConn2 = strConn2 & "DATA SOURCE=LQRES021;INITIAL CATALOG=LQAFCustom;"

strConn2 = strConn2 & "INTEGRATED SECURITY=SSPI;"
'Now open the connection.
cn.Open strConn2

' Create a recordset object.
Dim rst As ADODB.Recordset
Dim ResultSet
Set rst = New ADODB.Recordset

Sql = "exec dbo.dboTest"

rst.Open Sql, cn

rst.Close
cn.Close




Set rst = Nothing
Set cn = Nothing

End Sub


And the stored procedure that I am executing:


BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

--Create A Table to Put Data into
DECLARE @productionTable TABLE (ID INT IDENTITY(1,1),dataTime DATETIME,dataInput FLOAT)

INSERT INTO @productionTable (dataTime,dataInput)
--Get Data from AF View and Insert into the Production Table
SELECT convert(datetime,((Time)))as TimeStamp, round((Convert(float,(Value))),3) as Input_Production
FROM [AFLINK].[PIAFDB].[Data].[DigesterProdution]

select ID,dataTime,dataInput
From @productionTable

-- Get the number of rows in the looping table
DECLARE @RowCount INT
SET @RowCount = (SELECT COUNT(dataInput) FROM @productionTable)

-- Declare an iterator
DECLARE @I INT
-- Initialize the iterator
SET @I = 1

-- Loop through the rows of a table @myTable
WHILE (@I <= @RowCount)
BEGIN
-- Declare variables to hold the data which we get after looping each record
DECLARE @iID VARCHAR(50), @iTimestamp datetime, @iInputProduction float

-- Get the data from table and set to variables
SELECT @iID = ID, @iTimestamp = dataTime, @iInputProduction = dataInput FROM @productionTable WHERE ID = @I
-- Display the looped data
--PRINT 'Row No = ' + CONVERT(VARCHAR(2), @I)
--PRINT 'ID = ' + @iID + ', TimeStamp = ' + @iTimestamp + ' Production = '+ @iInputProduction

--Update PILINK.PIARCHIVE..PICOMP Set value = round((Convert(float,(@iInputProduction))),3)
--where tag = 'testtag' and time = convert(datetime,(@iTimestamp))
--Write Values To PI
INSERT INTO PILINK.PIARCHIVE..PICOMP (tag,time,value)
VALUES ('testtag',@iTimestamp,round(@iInputProduction,3))

-- Increment the iterator
SET @I = @I + 1
END
END




GO



What am I missing? I would appreciate any help.


I can also run the stored procedure from vba if I don't use integrated security; however, that doesn't meet our security guidelines.
Sponsor  
 

OSIsoft vCampus is a subscription-based, online offering that consists of providing everything people need to develop applications on the PI System.
We invite you to take a "tour" of the OSIsoft Virtual Campus - also feel free to consult the FAQ  or contact OSIsoft vCampus for more details.
blitzclipse
#2 Posted : Friday, February 11, 2011 7:33:04 PM
Rank: Member
Groups: Member

Joined: 1/15/2010
Posts: 13
Location: us
I solved the problem. It was an issue with sql not passing the credentials to the sdk.

I have found 2 solutions

1.
First: I created a job that executes the stored procedure under my sql server agent which is a domain account
Second: I created a stored procedure that starts the job.

CREATE PROCEDURE [dbo].[StartAgentJob]

AS BEGIN EXEC msdb.dbo.sp_start_job N'TEST';
END
GO

I can use windows security and specify on the sql level if they have the ability to execute the StartAgentJob stored procedure.


2.
You must have domain admin privileges to execute these commands. In this example, the SQL Server is listening on port 1433, which is the port assigned during installation to the default instance; be advised that it could be using a different port.
setspn -a mssqlsvc/mycomp.mydomain.com:1433 mydomain\domainuser
setspn -a mssqlsvc/mycomp.mydomain.com mydomain\domainuser
RJK Solutions
#3 Posted : Thursday, February 17, 2011 11:37:15 AM
Rank: Administration

Groups: Administration

Joined: 6/20/2008
Posts: 617
Location: Cheshire, United Kingdom.
Hi Kevin...

Yeah, your 2nd solution actually describes Allowing delegation for service accounts (kerberos)...it is the solution advised for the AF OLEDB provider too if the AF server is on a different server from the SQL Server.
Principal Consultant
Real-Time Data Management @ Wipro Technologies
Users browsing this topic
Guest
Forum Jump  
You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot delete your posts in this forum.
You cannot edit your posts in this forum.
You cannot create polls in this forum.
You cannot vote in polls in this forum.