0

I am trying to do some SQL stuff (back a database, restore a database, run some script files) as part of an MSBuild script. The Sql2008.Database task from the MSBuild Extension pack seemed to be a nice easy way of doing this, however i cannot find a way to specify a server instance or username and password. I find it hard to believe that it is limited to the default instance on the machine you are building on and want to connect as the user MSBuild is running but i can't find a way to do anything else. This is the documentation I am working from. Can anyone explain how to do this or do i need to look at a different approach?

Ben Robinson
  • 21,601
  • 5
  • 62
  • 79

3 Answers3

2

There are UserName and UserPassword properties you can use:

<MSBuild.ExtensionPack.Sql2008.Database 
MachineName="$(SQLServer)" 
TaskAction="Backup" 
DatabaseItem="$(SQLDatabaseName)" 
DataFilePath="$(SQLBackupLocation)" 
UserName="$(SQLUserName)"
UserPassword="$(SQLPassword)" />

Alex R
  • 191
  • 1
  • 6
1

I discovered that the MSBuild.ExtensionPack.BaseTask class has the properties MachineName UserName and UserPassword. SQL2008.Database class inherits from this class. I am used to MSDN style documentation where the inherited members are documented on the derived class so i did not think to look for them there although i should have. It does seem a strange place for them though as they are meaningless in the context of many of the other classes that inherit from MSBuild.ExtensionPack.BaseTask.

Ben Robinson
  • 21,601
  • 5
  • 62
  • 79
0

Doesnt that task have the MachineName member? Think thats just the sql instance name you need.

I use the task MSBuild.ExtensionPack.SqlServer.SqlExecute and a sql statement to do everything else e.g.

<MSBuild.ExtensionPack.SqlServer.SqlExecute TaskAction="ExecuteReader"
                                                Sql="RESTORE DATABASE $(DatabaseName) FROM  DISK = N'$(RestoreFileDestination)\Source\$(Branch)\Build\$(DatabaseFile)' WITH FILE = 1,MOVE N'Accelerate' TO N'$(dataDir)\$(DatabaseName)_1.LDF', MOVE N'Accelerate_log' TO N'$(logsDir)\$(DatabaseName)_2.LDF', NOUNLOAD, REPLACE, KEEP_CDC, STATS = 10"
                                                ConnectionString="Data Source=Localhost\SQLExpress;Initial Catalog=master;Integrated Security=True"
                                                CommandTimeout="660">

They'd never think of all the options i seem to need....

James Woolfenden
  • 6,498
  • 33
  • 53
  • No it does not have MachineName. I am looking at using the SqlExecute task as above but i would prefer to use the Sql2008.Database task if possible as the backup/restore options are part of the task definition rather than part of the SQL command. – Ben Robinson Sep 05 '11 at 14:45
  • in the help from the task: ? – James Woolfenden Sep 05 '11 at 14:46
  • OK i didn't notice that, i was looking at the members for the Database class defined here http://www.msbuildextensionpack.com/help/4.0.1.0/html/2dfa8205-e7ff-59bb-771b-d107fd8cb0da.htm and MachineName is not one of them. However that does not help with the specified username and password part of my problem. I need to run the script against a remote SQL server that is not part of a domain so i cannot use integrated windows authentication. – Ben Robinson Sep 05 '11 at 15:09
  • Sorry reading the above again it seems a bit rude, thank you very much for your help i may not have noticed the MachineName attribute without your help. – Ben Robinson Sep 05 '11 at 15:20
  • THe problem is that there is no ConnectionString attribute in the Sql2008.Database task and i cannot see an equivelent way to provide a connection string. – Ben Robinson Sep 05 '11 at 15:49