2

Almost done with my C# Password Generator/Store. All the passwords are stored in a local encypted database that is hashed and also has a DB password. I am using sql express/compact(whatever it is called) to create the database manually. I was wondering if there was a way to check if a database was already created and has the right tables included. Also is there a way if the DB is not created to tell it to create an encrypted DB? Also have it create a folder in a speceific location too if that is not there also create it and store the DB inside.

Thanks

1
  • does the database exists on a sql server or a physical file? you can just check if the connection exists or if the file exists for that. Commented May 26, 2011 at 2:00

2 Answers 2

2

You can run a query like this

  IF NOT EXISTS
   (  SELECT [name] 
      FROM sys.tables
      WHERE [name] = 'TableName`
   )
   CREATE TABLE TableName (Col1 int, Col2 int ... )

for each table in the right order.

Sign up to request clarification or add additional context in comments.

Comments

1

I was wondering if there was a way to check if a database was already created

Select * from sys.databases Where name = 'YourDatabaseName'

Alternative

Select * from sys.objects Where name = 'YourDatabaseName'

has the right tables included

Select * from sys.tables where name = 'YourTableName'

Alternative

Select * from sys.objects where name = 'YourTableName'

Also is there a way if the DB is not created to tell it to create an encrypted DB?

If Not Exists(Select * from sys.databases Where name = 'YourDatabaseName')
Begin
    --Create your database
End

Folder creation is the process during the database creation

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.