&
技术问答
215 人阅读
|
0 人回复
|
2023-09-14
|
> Array.ofSeq data :> System.Collections.IEnumerablestatic member Example8Row ((obj : Object),(ssn: SqlChars byref)) = do ssn string)) ()我在这里处理数百万行。有没有办法偷懒地做到这一点?
. b' K8 i0 K7 n8 C # y) x$ e; }2 x
解决方案: $ K6 W& `: _5 J
假设你用的是SQL Server2008。正如Microsoft本页员工提到的2008要求DataAccessKind标记方法。阅读频率远高于2005年。其中之一是当TVF参与事务时(当我进行测试时,情况似乎总是如此)。解决方案是enlist=false在连接字符串中指定,但不能与结合使用context connection=true。这意味着您的连接字符串必须采用典型的客户端格式:Data Source=.;Initial Catalog=MyDb;Integrated Security=sspi;Enlist=false而且你的程序集必须permission_set=external_access至少用于创作。以下作品:3 p! g# _5 U1 k# \; K; _
using System;using System.Collections;using System.Data.SqlClient;using System.Data.SqlTypes;using Microsoft.SqlServer.Server;namespace SqlClrTest public static class Test [SqlFunction( DataAccess = DataAccessKind.Read, SystemDataAccess = SystemDataAccessKind.Read, TableDefinition = "RowNumber int", FillRowMethodName = "FillRow" public static IEnumerable MyTest(SqlInt32 databaseID) using (var con = new SqlConnection("data source=.;initial catalog=TEST;integrated security=sspi;enlist=false")) con.Open(); using (var cmd = new SqlCommand("select top (100) RowNumber from SSP1 where DatabaseID = @DatabaseID",con)) cmd.Parameters.AddWithValue("@DatabaseID",databaseID.IsNull ? (object)DBNull.Value : databaseID.Value); using (var reader = cmd.ExecuteReader()) while (reader.Read())) yield return reader.GetInt32(0); public static void FillRow(object obj,out SqlInt32 rowNumber) { rowNumber = (int)obj; } }}这是F#同样的事情:# S+ ^, c* ^! f4 L
namespace SqlClrTestmodule Test = open System open System.Data open System.Data.SqlClient open System.Data.SqlTypes open Microsoft.SqlServer.Server [] let MyTest (databaseID:SqlInt32) = seq use con = new SqlConnection("data source=.;initial catalog=TEST;integrated security=sspi;enlist=false") con.Open() use cmd = new SqlCommand("select top (100) RowNumber from SSP1 where DatabaseID = @DatabaseID",con) cmd.Parameters.AddWithValue("@DatabaseID",if databaseID.IsNull then box DBNull.Value else box databaseID.Value) |
|
|
|
|
|