Testing SQL Stored Procedures using PowerShell
2009-02-13 20:49
411 查看
Suppose you have a SQL database named dbMovies which has a stored procedure usp_GetMovieDataByPrice. First launch a Visual Studio command shell and issue the command:
>sqlmetal.exe /server:(local) /database:dbMovies /sprocs /code:mapping.cs
This creates a C# file named mapping.cs. Next issue the command:
>csc.exe mapping.cs /target:library
This compiles the C# proxy code into a DLL library named mapping.dll which PowerShell can access. Now launch PowerShell and issue these commands:
> [Reflection.Assembly]::LoadFile('C:\mapping.dll')
> $cs = "server=(local);database=dbMovies;Trusted_Connection=true"
> $o = new-object dbMovies($cs)
> $o | get-member
> $ans = $o.Usp_GetMovieDataByPrice(11.11)
> $ans
And presto! You have called a SQL stored procedure using PowerShell. Very neat and easy. Once you can call a stored procedure, you can write a test harness which feeds input to the stored procedure and checks for an expected result to determine a pass/fail result.
相关文章推荐
- LINQ to SQL系列Part 7 - Updating our Database using Stored Procedures
- ScottGu博客之翻译-Linq to Sql第7部分--用存储过程更新数据库--LINQ to SQL (Part 7 - Updating our Database using Stored Procedures)
- Using Dynamic SQL Statements in Stored Procedures
- LINQ to SQL系列Part 6 - Retrieving Data Using Stored Procedures
- sql: MySQL and Microsoft SQL Server Stored Procedures IN, OUT using csharp code
- sql: MySQL and Microsoft SQL Server Stored Procedures IN, OUT using csharp code
- ScottGu之博客翻译-第6部分-用存储过程检索数据-LINQ to SQL (Part 6 - Retrieving Data Using Stored Procedures)
- sql: MySQL and Microsoft SQL Server Stored Procedures IN, OUT using csharp code
- Calling Stored Procedures Using the SQL Adapter
- Using DataAdapters and stored procedures with Sybase and ODBC.NET
- The Guru's guide to SQL server stored procedures, XML, and HTML
- Stored procedures versioning with SQL Server and Visual SourceSafe
- Creating recurive stored procedures in T-SQL.
- Testing an ASP.NET Web Service using PowerShell
- Professional SQL Server 2005 CLR Programming: with Stored Procedures, Functions, Triggers, Aggregate
- SQL Server Stored Procedures Optimization Tips
- Lesson 07: Using Stored Procedures(使用存储过程)
- List the Stored Procedures in a SQL Server database
- Snippet: Fetching results after calling stored procedures using MySQL Connector/Python
- Using NHibernate With Stored Procedures