How to use the vs.net debug data stock procedure Longrujun [original]

zhaozj2021-02-16  161

VS.NET can use languages ​​such as C # and VB.NET to develop .NET architectures, can also be used to write CSS (laminated style sheets), HTML, XML, and SQL. Among them, the functionality of SQL is often neglected by us. Here I explain in detail how vs.net works with SQL. The database connection VS.NET Server Explorer can be very convenient to implement the connection with the database server. Although this connection is not limited to SQL Server. Figure A shows the Server Explorer panel on the right side of the VS.NET workspace. You can find the object via the View drop-down menu, or click the tab to display the Server Explorer on the right side of the workspace. Right-click Data Connections in Server Explorer, which will appear options to connect to the new database. Figure B is a connection dialog. Where the Test Connection button can easily test the connectionability and connection correctness of the database. Figure A: Visual Studio .NET Server Explorer Figure B: Adding a new database connection via Server Explorer Once a connection is added to Server Explorer, it will appear in the server node of Server Explorer. At the same time, the server name and related options will appear below. The SQL Servers node can provide programs to access SQL Server's capabilities of data elements. Now, you can already start debugging SQL code, but some settings are required before this. SQL Server Sets SQL Server contains an extended stored procedure that can be used to control the access capabilities of the calling process. This stored procedure is called sp_sdidebug. The following T-SQL code can be used to allow a user to debug a stored procedure: Use master grant execute on sp_sdidebug to username In addition, the user must have access to the database and stored procedures. Once you do a good job, the user can start the real debugging process. In fact, the debugging process is very simple, just right-click the stored procedure in VS.NET Server Explorer, and select Step Into Stored Procedure. Figure C is an example of a stored procedure commissioning using the Northwind database. In this example, the stored procedure returns the highest price products from the database. Figure C: By the Server Explorer debug store process When the debugging process begins, it is nothing different from the daily debug C # or VB.NET code. Figure D is the view of the stored procedure in debug mode. The corresponding option can be implemented by the debug drop-down menu or shortcut. The following is a few shortcuts related to debug-related: F5: Continue Shift F5: Stop debugging F11: Single step into the F10: Single Step Skip SHIFT F11: Single Step Jump out Figure D: The stored procedure in debug mode is additional, you can Add breakpoints and view points to monitor debugging procedures. At the bottom of the VS.NET workspace, you can see the output result of the debugging process. Figure E shows the VS.NET workspace after debugging the stored procedure. From the graph, we can see debugging information: The return value of the stored procedure run is 0, which means that the run is successful.

Figure E: Debugging information after running the stored procedure We can also display the output result from the drop-down menu on the debug window as shown in Figure F. The actual output and Figure F are similar. Figure F: Viewing the output result parameter reality in the output of the stored procedure is more complicated than our example. Most of the actual stored processes can be accepted or returned to one or more parameters. The debugger with vs.net is also very simple, you can see the code running after adding different parameters. When debugging a stored procedure that needs to be input, there is a window that pops up to accept parameters. Figure G is a dialog box for receiving parameters. In this example, I chose to enter the starting and abort time stored procedure (annual sales), which will return sales in this period of time. In addition, in the input parameters, NULL or DEFAULT can also be selected, which can check if the stored procedure will have problems in the case of null values ​​and default values. Figure G: The debugging process of parameters summarizes VS.NET to develop, maintain and debug the storage process, so that it completely replaces the work of the Query Analyzer such as SQL Server. Author Blog:

http://blog.9cbs.net/longrujun/

转载请注明原文地址:https://www.9cbs.com/read-9083.html

New Post(0)