473,750 Members | 2,213 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

determining if an SQL database exists, etc.

93 New Member
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 2202
vecs
3 New Member
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 Recognized Expert Specialist
There are system tables that you can use to check if it's existing master.sysdatab ases; 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
5256
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 exists within a stored procedure using SQL. Any ideas? Thanks, Will foehammer@hotmail.com
2
1951
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 using ifstream for this, and I can tell if it opened or not. But if it doesn't open, how do I tell whether the file exists or not? Here's what I have so far:
7
2129
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 drives. Small relations are on one EIDE drive, and the logfiles are on the other EIDE drive. When running the task, below, the rest of the machine is not doing much. I do not remember where I saw it, but somewhere I got the idea that the number...
3
13704
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? Remove obvious from e-mail address. Gareth Tonnessen LuvTruth@att.netNOJUNK
6
3648
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 think my problem mainly lies in knowing the quirks of the Access object model. Basically, I'm looking for a method of determining if an Access database is open yet. AND I'm looking for a method that doesn't not require checking for an...
1
1365
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 having the user point to it using the Open File Dialog from an Options menu item, but the program should be able to determine the path to a named program without relying on user intervention. Thanks.
5
2688
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 the individual problem, it caused problems in other areas. This is because the DataSource that I use for my databinding changes and must be "rebound". Because there is only one situation where I need the If Not IsPostBack() condition, I think it...
13
6575
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 has no primary key. I'm having trouble expressing an update trigger that checks for existing rows, contemporary to the updated one, but exclusing the
3
3111
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 it wraps the operation in a transaction. (psuedocode below) public function createItem ($parent) { $this -database -beginTransaction (); $this -database -query ('INSERT INTO items (param1, param2 ... ) values (val1, val2 ... )');
0
9000
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8838
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9396
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9339
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8260
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6804
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6081
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4887
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2804
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.