Solved

Get error #5 when using SQL Server SMO in Windows Forms project

Posted on 2015-02-11
9
101 Views
Last Modified: 2015-02-13
I am trying to get a list of server databases from within my visual studio windows forms project. I am using the following to the a list of available servers and everything works ok:  

Dim dataTable = SmoApplication.EnumAvailableSqlServers(False)
 datServers.ValueMember = "Name"
 datServers.DataSource = dataTable

I am using this code to list all of the databases for the past servers.  It works fine and returns all of the databases for some servers but others I get a connection error.    All of the severs are SQL server 2008 R2  

  Dim server As New Microsoft.SqlServer.Management.Smo.Server(xServer)
            For Each db As Microsoft.SqlServer.Management.Smo.Database In server.Databases
                datCombo.Items.Add(db.Name)
            Next


I can figure out why it works for one sever but not the other.

Any help would be appreciated.
0
Comment
Question by:Mike_Stevens
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
9 Comments
 
LVL 34

Expert Comment

by:ste5an
ID: 40603498
Can you connect to the other server in SSMS? Do you have the appropriate permissions?
0
 

Author Comment

by:Mike_Stevens
ID: 40603517
permissions on both servers are the same.    

Also, when I an trying to list the databases for a particular server im not using a username or password and it works on one server.
0
 
LVL 50

Expert Comment

by:Vitor Montalvão
ID: 40603529
Error #5 is Access Denied. Are you sure the user exists in all SQL Server instances? And has the right privileges?
0
Complete VMware vSphere® ESX(i) & Hyper-V Backup

Capture your entire system, including the host, with patented disk imaging integrated with VMware VADP / Microsoft VSS and RCT. RTOs is as low as 15 seconds with Acronis Active Restore™. You can enjoy unlimited P2V/V2V migrations from any source (even from a different hypervisor)

 

Author Comment

by:Mike_Stevens
ID: 40604073
I understand that Error #5 is an access is denied error.      I am not passing a username or password and the machine that is making the call is part of the domain.
0
 
LVL 50

Expert Comment

by:Vitor Montalvão
ID: 40605096
Sure. But not passing a SQL user credential should mean that's using current user domain credential and is that user credential that you need to check if exists in all SQL Server instances.
0
 

Author Comment

by:Mike_Stevens
ID: 40605616
I am developing this on a Windows 7 laptop using VS2010 that is logged into the same domain and the SQL servers.   Both  of the SQL servers have a login configured that is the same as what I use to log in to the domain with my laptop.
0
 
LVL 50

Accepted Solution

by:
Vitor Montalvão earned 500 total points
ID: 40605622
The errors are always on the same SQL Server instances? If so, can you connect to that instances remotely?
0
 
LVL 50

Expert Comment

by:Vitor Montalvão
ID: 40608056
You've found the issue?
0
 

Author Comment

by:Mike_Stevens
ID: 40608234
no.  no solution.  I will keep tinkering with it
0

Featured Post

Best Practices: Disaster Recovery Testing

Besides backup, any IT division should have a disaster recovery plan. You will find a few tips below relating to the development of such a plan and to what issues one should pay special attention in the course of backup planning.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
In this article we will get to know that how can we recover deleted data if it happens accidently. We really can recover deleted rows if we know the time when data is deleted by using the transaction log.
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…
Are you ready to implement Active Directory best practices without reading 300+ pages? You're in luck. In this webinar hosted by Skyport Systems, you gain insight into Microsoft's latest comprehensive guide, with tips on the best and easiest way…

751 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