开发者

Getting Visual Studio to execute SQL queries

In the office we use Visual Studio 2008 with Team Foundation Server as our version control system.

The products we're developing are essentially Teradata SQL scripts and stored procedures that get deployed to run on the organisation's Teradata database via an automated scheduler.

Problem We Have:

Whenever we need to fix a defect or deliver a change, we check-out the code, copy it to another tool to make our changes, then once we're happy, we check it back into TFS. It would be brilliant to do everything in Visual Studio, but there are a few solutions we need to find first:

  1. SQL Syntax Highlighting
  2. Ability to Execute SQL Scripts (will Teradata's .NET Data Provider do the job?)
  3. Parameter Substitution

Surely syntax highlighting and SQL execution can be done somehow, but I'm particularly worried that the Parameter Substitution will be the blocker as I've never heard of Visual Studio doing anything like this.

How we use Parameter Substitution:

For parameter substitutio开发者_如何学JAVAn, we need the ability to use a parameter for our database names (or any text for that matter), so that when we execute the SQL, Visual Studio basically substitutes the parameters within the code to whatever we need for the data source we're connected to, whether it's a Development, Test or Production environment.

For example, we may have the query:

SELECT Client_Id, First_Name, Last_Name  
FROM <<Client Database>>.Client_Names

When we execute that from Visual Studio, we need it to do parameter substitution, so behind the scenes, the following is what's actually sent to the database server:

SELECT Client_Id, First_Name, Last_Name  
FROM Client.Client_Names

In the same way, if I do:

SELECT '<<Client Database>>'

It would return a result of 'Client' when connected to the Production server.

On the other hand, if I'm connected to the Development server, it would return 'DevA_Client'.

The tool we currently use to do this simply has the parameters with the values defined in a CSV file (i.e. Prod-params.csv). Then there's a setting in the tool to link Prod-params.csv to the Production data source connection. An example of what this CSV file looks like is:

<<Client Database>>,Client
<<Order Database>>,Order
<<SomeHistoricDate>>,CAST('1997-05-28' AS DATE)

I'd love someone to be able to point me in the direction to be able to do any of this stuff in Visual Studio.


All the task you arfe describing can be done by writing a Visual Studio AddIn package, even the syntax higligthing, but is not a trivial task. Anyway try to start from here: http://msdn.microsoft.com/en-us/library/bb166533.aspx . Basically you can do everithing by extending VS, so parameter replacement should be easy as well. Additionally, if you have a working .NET provider for your target db eventually executing the query should be the simpler task.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜