我有一个sql脚本设置为滚动到生产.我把各种项目包装成单独的交易.在我们创建存储过程的每个事务中.我收到错误消息
消息156,级别15,状态1,行4关键字"过程"附近的语法不正确.
我创建了这个示例脚本来说明
Begin Try
Begin Transaction
-- do a bunch of add/alter tables here
-- do a bunch of data manipulation/population here
-- create a stored proc
create procedure dbo.test
as
begin
select * from some_table
end
Commit
End Try
Begin Catch
Rollback
Declare @Msg nvarchar(max)
Select @Msg=Error_Message();
RaisError('Error Occured: %s', 20, 101,@Msg) With Log;
End Catch
Run Code Online (Sandbox Code Playgroud)
这个错误似乎意味着我无法在事务中创建存储过程,但我找不到任何其他说明的文档(也许google今天不是freindly).
我们的项目将文件存储在sql server db中作为blob.我想从数据库中获取文件并将多个文件附加到电子邮件而无需写入磁盘.
这是我到目前为止(一切正常,没有附件):
// snip
List<System.Net.Mail.Attachment> attachments = null;
// Attachments is a child list of Messagebody object holding Attachment ids
MessageBody.Attachments = MessageBodyAttachmentList.GetMessageBodyAttachmentList(this.MessageBody.ID);
if (MessageBody.Attachments != null && MessageBody.Attachments.Count > 0)
{
attachments = new List<Attachment>();
foreach (Library.Entity.Messaging.MessageBodyAttachment att in MessageBody.Attachments)
{
using (MemoryStream memoryStream = new MemoryStream())
{
// create a new attachment
Library.Attachments.Attachment attachment = Library.Attachments.Attachment.GetAttachment(att.AttachmentID);
byte[] contentAsBytes = attachment.FileData;// FileData holds byte[] that is the contents of the file
memoryStream.Write(contentAsBytes, 0, contentAsBytes.Length);
memoryStream.Seek(0, SeekOrigin.Begin);
// …Run Code Online (Sandbox Code Playgroud) 有人建议移动一个充满设置的表,其中每列是设置名称(或类型),行是客户及其各设置的相应设置.
ID | IsAdmin | ImagePath
------------------------------
12 | 1 |\path\to\images
34 | 0 | \路径\为\图片
这样做的缺点是每次我们想要一个新的设置名称(或类型),我们改变表(通过sql)并添加新的(列)设置名称/类型.然后更新行(以便每个客户现在都有该设置的值).
新表设计方案.建议是有一个用于设置名称的列和另一个用于设置的列.
ID | SettingName | SettingValue
----------------------------
12 | IsAdmin | 1
12 | ImagePath |\path\to\images
34 | IsAdmin | 0
34 | ImagePath | \路径\为\图片
他们提出的观点是,添加新设置就像对行的简单插入语句一样简单,没有添加列.
但是对于第二种设计来说感觉不对,它看起来很糟糕,但我无法提出反对它的任何论据.我错了吗?