[Webinar] Streamline your web hosting managementRegister Today

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

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

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
Mike_Stevens
Asked:
Mike_Stevens
  • 4
  • 4
1 Solution
 
ste5anSenior DeveloperCommented:
Can you connect to the other server in SSMS? Do you have the appropriate permissions?
0
 
Mike_StevensAuthor Commented:
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
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
Error #5 is Access Denied. Are you sure the user exists in all SQL Server instances? And has the right privileges?
0
Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

 
Mike_StevensAuthor Commented:
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
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
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
 
Mike_StevensAuthor Commented:
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
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
The errors are always on the same SQL Server instances? If so, can you connect to that instances remotely?
0
 
Vitor MontalvãoMSSQL Senior EngineerCommented:
You've found the issue?
0
 
Mike_StevensAuthor Commented:
no.  no solution.  I will keep tinkering with it
0

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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