tags:

views:

452

answers:

1

I am trying to create a SQL Server Express database using SMO like so:

Database db = new Database(server, dataSource);
...
db.Create();

I am able to use the database fine. But, if someone else tries to copy the database, they get file permission errors. In looking under the security tab in windows explorer, I am the only one who has permission. If I simply make a copy of the file, the copy gives everyone permissions.

So, what do I have to do in order for the Create() to give everyone permission? I would think that the file created would inherit the directory's permissions...but apparently not. I realize I could set the file permissions myself but would rather try to understand why the Create() is giving special permissions.

A: 

I think, you basically only need to add access for the "public" role - never tried it myself, but try this:

Database db = new Database(server, dataSource);
db.Roles.Add(new DatabaseRole(db, "public"));
db.Create();

Does that work? Can your coworkers access the database now?

Marc

marc_s
That doesn't work. It does add more permissions. But, then when I detach the created data source, the file permissions revert back to the user who created the file.Note that the database creation is done on a build machine under an adminstrative account. The build machine creates all the files and our development installation program grabs these files from the build server. But without having permissions, the developers don't get the DB files.I guess I will just make a file copy of the created db and it should work since the copy will inherit the folder's permissions.
bsh152s