Solved

OPENDATASOURCE Sometimes fails

Posted on 2010-11-18
9
1,173 Views
Last Modified: 2012-05-10
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
Comment
Question by:gdspeare
  • 5
  • 4
9 Comments
 
LVL 28

Expert Comment

by:sammySeltzer
Comment Utility
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
 
LVL 28

Expert Comment

by:sammySeltzer
Comment Utility
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
 

Author Comment

by:gdspeare
Comment Utility
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
 
LVL 28

Expert Comment

by:sammySeltzer
Comment Utility
>>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
Complete Microsoft Windows PC® & Mac Backup

Backup and recovery solutions to protect all your PCs & Mac– on-premises or in remote locations. Acronis backs up entire PC or Mac with patented reliable disk imaging technology and you will be able to restore workstations to a new, dissimilar hardware in minutes.

 

Author Comment

by:gdspeare
Comment Utility
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
 
LVL 28

Expert Comment

by:sammySeltzer
Comment Utility
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
 

Author Comment

by:gdspeare
Comment Utility
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
 
LVL 28

Accepted Solution

by:
sammySeltzer earned 500 total points
Comment Utility
0
 

Author Closing Comment

by:gdspeare
Comment Utility
not what I was hoping to learn, but it seems like this is my answer.  Thanks.
0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
SQL Server Log File Space 6 33
Need Counts 11 40
Extract XML Data from using TSQL 5 28
Managing SQL log files, SQL Server 2014 6 54
In this article—a derivative of my DaytaBase.org blog post (http://daytabase.org/2011/06/18/what-week-is-it/)—I will explore a few different perspectives on which week today's date falls within using Microsoft SQL Server. First, to frame this stu…
JSON is being used more and more, besides XML, and you surely wanted to parse the data out into SQL instead of doing it in some Javascript. The below function in SQL Server can do the job for you, returning a quick table with the parsed data.
Via a live example, show how to extract information from SQL Server on Database, Connection and Server properties
Viewers will learn how to use the UPDATE and DELETE statements to change or remove existing data from their tables. Make a table: Update a specific column given a specific row using the UPDATE statement: Remove a set of values using the DELETE s…

771 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now