1

I am getting

Incorrect syntax near 'ABC.Security.GetUserLocation'.

when executing a stored procedure with the following code.

. dots are the part of Name (for grouping), don't confuse it with Schema.

Something like "FirstName.LastName". I can execute it from SSMS without any problem.

var userNameToSearch = new SqlParameter("@userName", userName);
userNameToSearch.DbType = System.Data.DbType.String;
userNameToSearch.Size = 100;

List<Location> locations = db.Database.SqlQuery<Location>(@"[ABC.Security.GetUserLocation]", userNameToSearch).ToList();

return locations;

What would be the right way to use names like that from C# code ?

2

2 Answers 2

1

Try to be explicit with your parameters

List<Location> locations = db.Database.SqlQuery<Location>(@"exec [ABC.Security.GetUserLocation] {0}", userNameToSearch).ToList();

"{0}" means that you are passing userNameToSearch as first parameter, doesnt matter whats the parameter's name.

Sign up to request clarification or add additional context in comments.

1 Comment

The first parameter need to be string value(or literal value) and not an SQLParameter at for SQL 2005 Version.
1

You can call a stored procedure in your DbContext class as follows.

this.Database.SqlQuery<YourEntityType>("storedProcedureName",params);

here more information : https://msdn.microsoft.com/en-us/data/jj691402.aspx

this was an answer from this question : here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.