microsoft / sqlmanagementobjects

Sql Management Objects, an API for scripting and managing SQL Server and Azure SQL Database
Other
130 stars 21 forks source link

Unable to create a default DataFile object on a ManagedInstance database #34

Open Matteo-T opened 3 years ago

Matteo-T commented 3 years ago

Run the following code snippet (tweak the connection string ("...") to point to a ManagedInstance server):

var dbname = "bugDB";
var srvconn = new ServerConnection(new SqlConnection("..."));
var srv3 = new SMO.Server(srvconn);
var db = new SMO.Database(srv3, dbname);
db.Create();

DataFile df = new DataFile(db.FileGroups[0], "MatteoDF"); 
df.Create();

It won't work.

If you set some properties on the DataFile object before the creation, it'll work.

Matteo-T commented 3 years ago

Note to self (and David): I've fixed in commit 2da04aab2e9a00802d512649f47b62889a48a7a4. It'll go out with the next release of the SMO package.