Error running query

Hi there

I'm having a problem running a simple query from with my VB code. I can connect to the local instance of SQL 2012 Express using a connectionstring of : "Data Source=MyComputerName\SQLEXPRESS;Initial Catalog=master;Integrated Security=SSPI" but after I get connected and try to run this query I get an error: "Select name from master.dbo.sysdatabases where name = N'MyDatabaseName'"

Any ideas why? Could it be a firewall issue?

June 29th, 2015 4:09pm

What error message is returned?

Free Windows Admin Tool Kit Click here and download it now
June 29th, 2015 4:15pm

Depends on the error message. the query looks ok. What is the message?
June 29th, 2015 4:18pm

The message is indicating no authority to run the query. Is there a difference between master.dbo.sysdatabases and sys.databases?
Free Windows Admin Tool Kit Click here and download it now
June 29th, 2015 5:32pm

Yep. Context.

MASTER is a database, which you probably don't have access to (unless your an admin).

[database].[schema].[table]

If you don't fully qualify an object, assumptions are made. If you omit database, the current database is assumed. If you omit schema, your default schema is assumed.

You may have rights to connect to master, but not select from it.

June 29th, 2015 5:35pm

So does that mean I should use sys.databases instead of master.dbo.sysdatabases ? I am connecting to the server with Initial Catal
Free Windows Admin Tool Kit Click here and download it now
June 29th, 2015 6:03pm

It's better, imo, to use explicit paths, especially when making calls outside of sql server (ie, from your application) as this way you KNOW where your objects are going.
June 29th, 2015 6:04pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics