0

Trying to generate an output file in Codesmith Generator (csg).

I am using ADOXSchemaProvider to access a sql database. Am getting this error on a trivial table (1 varchar(50) field)

The syntax of the message seems to indicate the problem is rooted in CSG trying to access properties in a list/collection. Some of the other SO questions (unrealted to CSG )have suggested using reserved words could be the problem, so I am using a jumble of letters. Not the issue.

I have uninstalled / reinstalled.

Target table script is this

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

) ON [PRIMARY]

GO

Error call stack is this

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()

and line 113 of my template is the first line of this code paragraph

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

Also, I did investigate whether possibly the ADOX provider uses 1 as a base for the columns index.

Problem persists if i do either of these.

<%=  SourceTable.Columns.Clear    %>
<%=  SourceTable.Columns.Item(0)    %>
greg
  • 1,673
  • 1
  • 17
  • 30
  • Does this help answer your question? http://stackoverflow.com/questions/24620324/item-cannot-be-found-in-the-collection-corresponding-to-the-requested-name-or-or – Rob Oct 30 '16 at 22:37
  • @Rob I dont think so but its hard to tell. I think that op had a basic SP problem as far as I can tell. I am accessing the local database as SA so I doubt it is a security problem. I can not find a securables tab on any of User, login , Role properties. I am using Microsoft SQL Server Business Intelligence (64-bit) 12.0.4459.0 – greg Oct 31 '16 at 10:43

1 Answers1

1

Per codesmith, you should always access a sql server database w/ the SQLSchemaProvider.

I was trying to do this because i have an intermittent issue where the SQL datasources fail w/ a division by 0 error.

Adding a datasource to Codesmith

Community
  • 1
  • 1
greg
  • 1,673
  • 1
  • 17
  • 30
  • Yes, I'm a developer at CodeSmith Tools and I'd never use anything but the SqlSchemaProvider when using Sql Server. It's heavily tested against Sql Server... – Blake Niemyjski Jul 07 '17 at 01:58