2016-10-30 14 views
0

嘗試在Codesmith Generator(csg)中生成輸出文件。Codesmith - 在與請求的名稱或序號對應的集合中找不到項目

我正在使用ADOXSchemaProvider訪問sql數據庫。 (1 varchar(50)字段)

該消息的語法似乎表明問題是根植於CSG試圖訪問列表/集合中的屬性。其他一些SO問題(CSG未實現)提示使用保留字可能是問題,所以我使用了一堆字母。不是問題。

我已卸載/重新安裝。

目標表的腳本是這樣的

CREATE TABLE [dbo].[tblWitsEnd](
    --[Id] [int] IDENTITY(1,1) NOT NULL, 
    asdf varchar(255) null 

) ON [PRIMARY] 

GO 

錯誤調用堆棧是這樣的

Error: Item cannot be found in the collection corresponding to the requested name or ordinal. 
Stack Trace: 
    at ADOX.Properties.get_Item(Object Item) 
    at SchemaExplorer.ADOXSchemaProvider.GetTableColumns(String connectionString, TableSchema table) 
    at SchemaExplorer.TableSchema.#o4c() 
    at SchemaExplorer.TableSchema.get_Columns() 
    at _CodeSmith.StartingBlocks30_cst.__RenderMethod1(TextWriter writer, Control control) in G:\csgtemplate.cst:line 113 
    at CodeSmith.Engine.DelegateControl.Render(TextWriter writer) 
    at CodeSmith.Engine.Control.RenderChildren(TextWriter writer) 
    at CodeSmith.Engine.CodeTemplate.Render(TextWriter writer) 
    at CodeSmith.Engine.CodeTemplate.RenderToString() 
    at CodeSmith.Engine.Remoting.TemplateSession.#9Hb() 
    at System.Threading.Tasks.Task`1.InnerInvoke() 
    at System.Threading.Tasks.Task.Execute() 

和線路113我的模板是該代碼段

<% for i = 0 to SourceTable.Columns.Count - 1 step 1 %> 
    <%= GetSetFieldSnippet(SourceTable.Columns(i)) %> 
<% next %> 

而且第一線,我確實調查了ADOX提供者是否使用1作爲列索引的基礎。

如果我這樣做,問題仍然存在。

<%= SourceTable.Columns.Clear %> 
<%= SourceTable.Columns.Item(0) %> 
+0

這有助於回答您的問題嗎? http://stackoverflow.com/questions/24620324/item-cannot-be-found-in-the-collection-corresponding-to-the-requested-name-or-or – Rob

+0

@Rob我不這麼認爲,但很難告訴。據我所知,我認爲這個操作系統有一個基本的SP問題。我以SA身份訪問本地數據庫,所以我懷疑這是一個安全問題。我無法在任何用戶,登錄名,角色屬性中找到安全選項卡。我正在使用Microsoft SQL Server商業智能(64位)12.0.4459.0 – greg

回答

1

對於每個codesmith,您應該始終訪問SQLSchemaProvider的sql server數據庫。

我正在嘗試這樣做,因爲我有一個間歇性問題,SQL數據源失敗w /除0錯誤。

Adding a datasource to Codesmith

+0

是的,我是CodeSmith Tools的一名開發人員,在使用Sql Server時,除了SqlSchemaProvider之外,我從不使用其他任何軟件。它對Sql Server進行了大量測試... –

相關問題