[Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1439
  • Last Modified:

OPENDATASOURCE Sometimes fails

I have a view created by OPENDATASOURCE.  The view is

SELECT *
FROM OPENDATASOURCE ('SQLNCLI','Data Source = mydatasource;trusted_connection=yes')
.dbname.tablename

Randomly I get the following error when I run a select on the view from my workstation.

Msg 18456, Level 14, State 1, Line 1

Login failed for user 'NT AUTHORITY\ANONYMOUS LOGON'.

OLE DB provider "SQLNCLI" for linked server "(null)" returned message "Invalid connection string attribute".

 

If I immediately log into the server and run it there (with no problems) I can jump back to my desktop and run it (almost like I cleaning out some memory or something).

 

So I wanted to see if there was an execution count that would trigger the error.  I ran a loop selecting * from the view for well over an hour on my machine..  The query was executed over 225,000 times.  When it was done, I ran the select statement alone ~5 times with no problems.  I leave my session for a few minutes I come back and get the error again and of course log into the server run it come backā€¦no problems.

 
Any ideas?
0
gdspeare
Asked:
gdspeare
  • 5
  • 4
1 Solution
 
sammySeltzerCommented:
Try using integrated security like:


SELECT *
FROM OPENDATASOURCE ('SQLNCLI','Data Source = mydatasource;Integrated Security=SSPI')
.dbname.tablename

Open in new window


because you are using trusted connection, anonymous login will always fail.
0
 
sammySeltzerCommented:
No, use standard security is what I meant, sorry.

Integrated security and trusted connection set to true are the same.

So, should be:

SELECT *
FROM OPENDATASOURCE ('SQLNCLI','Data Source = mydatasource;UserId=Your_Username;Password=Your_Password')
.dbname.tablename
0
 
gdspeareAuthor Commented:
why do you think think this would address the ocassional error?  I can run it just fine.  

plus this is going into an app.  users won't be entering any credentials.
0
Get free NFR key for Veeam Availability Suite 9.5

Veeam is happy to provide a free NFR license (1 year, 2 sockets) to all certified IT Pros. The license allows for the non-production use of Veeam Availability Suite v9.5 in your home lab, without any feature limitations. It works for both VMware and Hyper-V environments

 
sammySeltzerCommented:
>>plus this is going into an app.  

Web app, you mean? Your original post didn't indicate that.

if it is .net, you may wish to consider adding <impersonate = "True">

>>users won't be entering any credentials.

True. They don't have to because once you create an account on the db useing SQL Server Authentication Mode and add you give it read or execute or whatever permission you wish to give it, and you enter that account into your code as I indicated, then it will authenticate any user accessing the app.

0
 
gdspeareAuthor Commented:
what you are suggesting makes sense. However, it doesn't aswer the question of why my query bombs out from my workstation after some event (which i can't identify) and then is successful after I run the query on the server directly.  

I'm also not convinced that I would get the same issue b/c I'm an admin on both boxes.  So if i'm running into this issue a sql specific account would too
0
 
sammySeltzerCommented:
What I think is happening is that in your iis, you are using windows integrated authentication which means that anyone accessing your app must be a windows domain user.

So, when you log in as an admin, by default, you have sysadmin account and things work fine.

If you try to run without a domain account, you run into the issue you are having.

So, the decision you have to make is whether to allow all users to have domain account OR, you do as I suggested and use ONE SQL Server account that has both execute and and atleast readOnly permission.
0
 
gdspeareAuthor Commented:
i'm not using IIS - I'm logged into the server user SSMSE on my workstation and when the query fails I log into a full install on the server.

I haven't integreated the query into the asp app because of this issue.
0
 
sammySeltzerCommented:
0
 
gdspeareAuthor Commented:
not what I was hoping to learn, but it seems like this is my answer.  Thanks.
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now