如何在vb.net网站中添加c#名称空间? [英] How can add c# namespace in a vb.net Website?

查看:82
本文介绍了如何在vb.net网站中添加c#名称空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Hello Codian,

我想在网站[不是Web应用程序]中创建两个名称空间,但是问题是一个名称空间应该位于vb.net中,另一个名称空间应该位于c#.net中.
那怎么可能呢?我的问题是默认网站位于vb.net中,其他名称pce应该位于c#.net中,那么如何将用户从vb.net表单重定向到c#.net表单?

谢谢
Mhbalti

Hello Codian,

I want to create two namespaces in a website[not web application] , but the problem is one namespace should be in vb.net and the other in c#.net.

So how is it possible? My problem is that the default website is in vb.net and the other namespce should be in c#.net, so how can I redirect user from vb.net form to c#.net form?

Thanks
Mhbalti

推荐答案

Hello Buddy.

那些命名空间是什么?
Hello Buddy.

what are those namespaces?


使用RAISERROR
SQL Server 2008 R2
其他版本

RAISERROR用于使用与SQL Server数据库引擎生成的系统错误或警告消息相同的格式将消息返回给应用程序.

RAISERROR可以返回以下任意一个:

使用sp_addmessage系统存储过程创建的用户定义错误消息.这些是消息号大于50000的消息,可以在sys.messages目录视图中查看.

在RAISERROR语句中指定的消息字符串.

RAISERROR也可以:

分配特定的错误编号,严重性和状态.

要求将错误记录在数据库引擎错误日志和Microsoft Windows应用程序日志中.

将参数值替换为消息文本,就像C语言的printf_s函数一样.

RAISERROR和PRINT均可用于将信息或警告消息返回给应用程序.可以使用类似于C标准库的printf_s函数的字符串替换功能来构建RAISERROR返回的消息文本,而PRINT只能返回字符串或字符表达式.在TRY…CATCH构造的TRY块中执行的RAISERROR严重性为11到19,导致控制权转移到关联的CATCH块.将严重性指定为10或更低,以使用RAISERROR返回消息而不调用CATCH块. PRINT不会将控制权转移到CATCH块.

当RAISERROR与sys.messages中用户定义的消息的msg_id一起使用时,msg_id将作为SQL Server错误号或本机错误代码返回.当RAISERROR与msg_str而不是msg_id一起使用时,SQL Server错误号和返回的本机错误号为50000.
当您使用RAISERROR返回用户定义的错误消息时,请在引用该错误的每个RAISERROR中使用不同的状态号.这可以帮助在错误出现时进行诊断.

使用RAISERROR可以:

帮助对Transact-SQL代码进行故障排除.

检查数据值.

返回包含可变文本的消息.

导致执行从TRY块跳转到关联的CATCH块.

将错误信息从CATCH块返回到调用批处理或应用程序.

下面的示例在发送回应用程序的消息中替换DB_ID()和DB_NAME()函数中的值:
其他

DECLARE @DBID INT;
SET @DBID = DB_ID();

DECLARE @DBNAME NVARCHAR(128);
SET @DBNAME = DB_NAME();

RAISERROR
(N''当前数据库ID为:%d,数据库名称为:%s.'',
10-严重性.
1,-状态.
@DBID-第一个替换参数.
@DBNAME); -第二个替换参数.
GO

此示例使用用户定义的消息提供相同的信息.
其他

执行sp_dropmessage 50005;
GO
EXECUTE sp_addmessage 50005,-消息ID号.
10-严重性.
N''当前数据库ID为:%d,数据库名称为:%s.'';
GO
DECLARE @DBID INT;
SET @DBID = DB_ID();

DECLARE @DBNAME NVARCHAR(128);
SET @DBNAME = DB_NAME();

RAISERROR(50005,
10-严重性.
1,-状态.
@DBID-第一个替换参数.
@DBNAME); -第二个替换参数.
GO

下面的代码示例演示如何在TRY块内使用RAISERROR导致执行跳转到关联的CATCH块.它还显示了如何使用RAISERROR返回有关调用CATCH块的错误的信息.
注意注意

RAISERROR只能生成状态为1到127的错误.由于数据库引擎可能会引发状态为0的错误,因此建议您先检查ERROR_STATE返回的错误状态,然后再将其作为值传递给RAISERROR的状态参数.
其他

开始尝试
-严重性为11-19的RAISERROR将导致执行
-跳转到CATCH块
RAISERROR(``在TRY块中引发错误.'',-消息文本.
16,-严重程度.
1-状态.
);
结束尝试
开始捕捉
宣告@ErrorMessage NVARCHAR(4000);
声明@ErrorSeverity INT;
DECLARE @ErrorState INT;

SELECT @ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();

-在CATCH块中使用RAISERROR返回
-有关原始错误的错误信息,
-导致执行跳转到CATCH块.
RAISERROR(@ErrorMessage,-消息文本.
@ErrorSeverity,-严重程度.
@ErrorState-状态.
);
结束观看;
Using RAISERROR
SQL Server 2008 R2
Other Versions

RAISERROR is used to return messages back to applications using the same format as a system error or warning message generated by the SQL Server Database Engine.

RAISERROR can return either:

A user-defined error message that has been created using the sp_addmessage system stored procedure. These are messages with a message number greater than 50000 that can be viewed in the sys.messages catalog view.

A message string specified in the RAISERROR statement.

RAISERROR can also:

Assign a specific error number, severity, and state.

Request that the error be logged in the Database Engine error log and the Microsoft Windows application log.

Substitute argument values into the message text, much like the C language printf_s function.

Both RAISERROR and PRINT can be used to return informational or warning messages to an application. The message text returned by RAISERROR can be built using string substitution functionality similar to the printf_s function of the C standard library, whereas PRINT can only return a character string or character expression. A RAISERROR severity of 11 to 19 executed in the TRY block of a TRY…CATCH construct causes control to transfer to the associated CATCH block. Specify a severity of 10 or lower to return messages using RAISERROR without invoking a CATCH block. PRINT does not transfer control to a CATCH block.

When RAISERROR is used with the msg_id of a user-defined message in sys.messages, msg_id is returned as the SQL Server error number, or native error code. When RAISERROR is used with a msg_str instead of a msg_id, the SQL Server error number and native error number returned is 50000.

When you use RAISERROR to return a user-defined error message, use a different state number in each RAISERROR that references that error. This can help in diagnosing the errors when they are raised.

Use RAISERROR to:

Help in troubleshooting Transact-SQL code.

Check the values of data.

Return messages that contain variable text.

Cause execution to jump from a TRY block to the associated CATCH block.

Return error information from the CATCH block to the calling batch or application.

The following example substitutes the values from the DB_ID() and DB_NAME() functions in a message sent back to the application:
other

DECLARE @DBID INT;
SET @DBID = DB_ID();

DECLARE @DBNAME NVARCHAR(128);
SET @DBNAME = DB_NAME();

RAISERROR
(N''The current database ID is:%d, the database name is: %s.'',
10, -- Severity.
1, -- State.
@DBID, -- First substitution argument.
@DBNAME); -- Second substitution argument.
GO

This example provides the same information using a user-defined message.
other

EXECUTE sp_dropmessage 50005;
GO
EXECUTE sp_addmessage 50005, -- Message id number.
10, -- Severity.
N''The current database ID is: %d, the database name is: %s.'';
GO
DECLARE @DBID INT;
SET @DBID = DB_ID();

DECLARE @DBNAME NVARCHAR(128);
SET @DBNAME = DB_NAME();

RAISERROR (50005,
10, -- Severity.
1, -- State.
@DBID, -- First substitution argument.
@DBNAME); -- Second substitution argument.
GO

The following code example shows how to use RAISERROR inside a TRY block to cause execution to jump to the associated CATCH block. It also shows how to use RAISERROR to return information about the error that invoked a CATCH block.
NoteNote

RAISERROR can generate errors with state from 1 through 127 only. Because the Database Engine may raise errors with state 0, we recommend that you check the error state returned by ERROR_STATE before passing it as a value to the state parameter of RAISERROR.
other

BEGIN TRY
-- RAISERROR with severity 11-19 will cause execution to
-- jump to the CATCH block
RAISERROR (''Error raised in TRY block.'', -- Message text.
16, -- Severity.
1 -- State.
);
END TRY
BEGIN CATCH
DECLARE @ErrorMessage NVARCHAR(4000);
DECLARE @ErrorSeverity INT;
DECLARE @ErrorState INT;

SELECT @ErrorMessage = ERROR_MESSAGE(),
@ErrorSeverity = ERROR_SEVERITY(),
@ErrorState = ERROR_STATE();

-- Use RAISERROR inside the CATCH block to return
-- error information about the original error that
-- caused execution to jump to the CATCH block.
RAISERROR (@ErrorMessage, -- Message text.
@ErrorSeverity, -- Severity.
@ErrorState -- State.
);
END CATCH;


这篇关于如何在vb.net网站中添加c#名称空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆