Reputation: 71
I am new to writing MSBuild scripts and I have made a basic script using VS2010, which outputs basic "Hello World" onto the console. However, I do have years of experience in java c# andC++ in VS2010 and Eclipse.I would want to basically have a script that uses SQL calls to connect to a database and then have queries that would check between the database that I connected to and an EXCEL sheet that I have imported. Is this possible with MSBUILD? Is it even possible to import an excel sheet into a script to write queries against it? I would need to ultimately put this script in a web page so I wouldn't have access to the VS2010 database tools from the best of my knowledge. I am not sure if I should use another program or continue using MSBUILD.
I have been reading around the web and have bumped into a few options but I cannot get a definitive answer on what my best option is to write a Script that connects to a SQL database.
Edit: Where would I put the database connection in a script? Would the connection be similar to that of java?
ConnectionManager cm;
System.Data.SqlClient.SqlConnection sqlConn;
System.Data.SqlClient.SqlCommand sqlComm;
cm = Dts.Connections["conectionManager1"];
sqlConn = (System.Data.SqlClient.SqlConnection)cm.AcquireConnection(Dts.Transaction);
sqlComm = new System.Data.SqlClient.SqlCommand("your SQL Command", sqlConn);
sqlComm.ExecuteNonQuery();
cm.ReleaseConnection(sqlConn);
Upvotes: 1
Views: 135
Reputation: 21711
If by "script" you mean MSBuild tasks, the MSBuild Extension Pack has tasks for reading and writing to SQL Server.
I do not know if it has tasks for Excel, but it has WMI tasks which you should be able to control Excel with. If you already have .NET code to do whatever it is you want, you can create your own .NET tasks for MSBuild with Task Factory.
In answer to your question about where to put the database connection string, the convention is to create a property in your MSBuild file PropertyGroup
such as
<PropertyGroup>
...
<YourConnectionString>Data Source=whatever, ...</YourConnectionString>
</PropertyGroup>
You can use these properties in your MSBuild tasks with syntax like:
<TaskName TaskConnectionStringAttribute="$(YourConnectionString)" />
Upvotes: 2