473,396 Members | 2,011 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

determining if an SQL database exists, etc.

Could someone please give me the simplest possible C# code snippets / SQL queries to determine whether:

* a given SQL database exists,
* a given existing SQL database is accessible, and
* a given table exists within a given existing SQL database?

Thanks for whatever help anyone can provide.
Apr 12 '09 #1
2 2191
vecs
3
List all accessible databases on server:
Expand|Select|Wrap|Line Numbers
  1. EXEC master..sp_databases
List all system tables, tables, views in current database:
Expand|Select|Wrap|Line Numbers
  1. EXEC sp_tables
List all tables with given name in specific database:
Expand|Select|Wrap|Line Numbers
  1. USE database_name
  2. EXEC sp_tables @table_name = '_user'
Apr 14 '09 #2
ck9663
2,878 Expert 2GB
There are system tables that you can use to check if it's existing master.sysdatabases; sysobjects - for the tables...to check if it's accessible, let your front-end connection handle it. Establish your connection and just throw an error. "Accessible" is a relative. It might be there but depending on the user account, it might not be "accessible"


--- CK
Apr 15 '09 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Foehammer | last post by:
Hey, I'm writing some automated unit tests for a database app. The app creates a database via script. I'm developing the system in a test-driven manner and need a way to determine if a parameter...
2
by: Rob Mandeville | last post by:
I need to open a file, and determine if: 1: I actually opened it 2: I couldn't open it because it doesn't exist, or 3: I couldn't open it for other reasons, such as file permissions. I'm...
7
by: Jean-David Beyer | last post by:
I have six hard drives (4 SCSI and 2 EIDE) on my main machine with parts of a database on each drive. The main index is on one SCSI drive all to itself. The main data are on the other three SCSI...
3
by: Gareth Tonnessen | last post by:
I need to have a clean way to determine whether a query exists without trying to open it and getting an error message. Is there a simple way to determine whether an object exists in a database?...
6
by: Kenneth Courville | last post by:
Hello, I'm looking for assistance with the Access object model. I know this is VB, but I'm building an Office Add-using C# directed at Access 2002. I'm literate in VB, so you can reply in VB... I...
1
by: Phil Galey | last post by:
In VB.NET, when you use shell or have a process object point to and run a separate application that is installed on the machine, is there a way of determining the path to the executable? I've been...
5
by: Nathan Sokalski | last post by:
I have a DataList that I was having trouble getting the events for. After a bit of help, I realized that I needed to put the databinding inside an If Not IsPostBack() condition. Although this fixed...
13
by: dennis | last post by:
Hello, I'm having trouble solving the following problem with DB2 UDB 8.2. I need to create a trigger that performs certain extra constraint validations (temporal uniqueness). One of the tables...
3
by: Gordon | last post by:
I am currently working on some code for my CMS that creates a site folder, then creates all the necessary child folders inside it. The method that creates folders needs to insert into 2 tables so...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.