usausa / Smart-Net-Data-Accessor

2-way/outside SQL build-time data accessor generator library.
MIT License
24 stars 3 forks source link

Incorrect syntax near '@_p0' when executed #8

Closed jay-dev-9 closed 3 years ago

jay-dev-9 commented 3 years ago

Hi Usausa,

I execute the code and get the error as below:


System.Data.SqlClient.SqlException (0x80131904): Incorrect syntax near '@_p0'.
   at void System.Data.SqlClient.SqlConnection.OnError(SqlException exception, bool breakConnection, Action<Action> wrapCloseInAction)
   at void System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, bool breakConnection, Action<Action> wrapCloseInAction)
   at void System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, bool callerHasConnectionLock, bool asyncClose)
   at bool System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, out bool dataReady)
   at bool System.Data.SqlClient.SqlDataReader.TryConsumeMetaData()
   at _SqlMetaDataSet System.Data.SqlClient.SqlDataReader.get_MetaData()
   at void System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, string resetOptionsString)
   at SqlDataReader System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, bool returnStream, bool async, int timeout, out Task task, bool asyncWrite, SqlDataReader ds)
   at SqlDataReader System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, bool returnStream, TaskCompletionSource<object> completion, int timeout, out Task task, bool asyncWrite, string method)
   at SqlDataReader System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, bool returnStream, string method)
   at SqlDataReader System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior behavior)
   at DbDataReader System.Data.SqlClient.SqlCommand.ExecuteDbDataReader(CommandBehavior behavior)
   at DbDataReader System.Data.Common.DbCommand.ExecuteReader(CommandBehavior behavior)
   at T Smart.Data.Accessor.Engine.ExecuteEngine.QueryFirstOrDefault<T>(DbCommand cmd)

this is automatically generated code

<img width="644" alt="Screenshot 2021-01-21 091918" src="https://user-images.githubusercontent.com/62498298/105271260-c49b5380-5bc9-11eb-97b5-78339215d99a.png">

[image](https://user-images.githubusercontent.com/62498298/105271100-80a84e80-5bc9-11eb-9a48-14d5d808c229.png)

Thanks for your support.
usausa commented 3 years ago

Sequence names cannot be treated as parameters in ADO.NET. Use the raw parameter for this case.

SELECT NEXT VALUE FOR /*@ sequence */sample
SELECT NEXT VALUE FOR /*# sequence */sample
jay-dev-9 commented 3 years ago

SELECT NEXT VALUE FOR /@ sequence /sample => it works in postgresql, not working in sql server. SELECT NEXT VALUE FOR /# sequence /sample => Ok in sql server

i don't know how it works

usausa commented 3 years ago

That's the difference between the implementations of each ADO.NET Data Provider. Even when using other libraries, SQL Server will use strings instead of parameters. Raw parameter version also works with PostgreSQL, so if you want to write it the same way, use raw parameter.

jay-dev-9 commented 3 years ago

I can see that, thank you