Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot Delete #383

Open
johnsev opened this issue Feb 13, 2016 · 10 comments
Open

Cannot Delete #383

johnsev opened this issue Feb 13, 2016 · 10 comments

Comments

@johnsev
Copy link

johnsev commented Feb 13, 2016

I am able to read, create, and update records but I cannot delete. I am using DeleteById(160) where the Id is currently hard coded. Here is the message I receive.

Format of the initialization string does not conform to specification starting at index 0.

I have noticed that others have similar problem but nothing I have tried is working. Again, the connection string works for everything but Delete. My connection string is...
Server=athena;Database=Appil;User Id=ABC;password=def;multipleactiveresultsets=True;

I am accessing the database over VPN - could that be a problem?

@rippo
Copy link

rippo commented Feb 13, 2016

Strange it ought to work, what happens if you try

var id = 160;
.DeleteById(id)

or

.Delete(Id: 160)

@johnsev
Copy link
Author

johnsev commented Feb 13, 2016

I get the same error message in all cases. I even tried creating a stored procedure where I simply pass the ID and the sp deletes the record. I get the same error message. Here is the full error message.

{
"Message": "An error has occurred.",
"ExceptionMessage": "Format of the initialization string does not conform to specification starting at index 0.",
"ExceptionType": "System.ArgumentException",
"StackTrace": " at System.Data.Common.DbConnectionOptions.GetKeyValuePair(String connectionString, Int32 currentPosition, StringBuilder buffer, Boolean useOdbcRules, String& keyname, String& keyvalue)\r\n at System.Data.Common.DbConnectionOptions.ParseInternal(Hashtable parsetable, String connectionString, Boolean buildChain, Hashtable synonyms, Boolean firstKey)\r\n at System.Data.Common.DbConnectionOptions..ctor(String connectionString, Hashtable synonyms, Boolean useOdbcRules)\r\n at System.Data.SqlClient.SqlConnectionString..ctor(String connectionString)\r\n at System.Data.SqlClient.SqlConnectionFactory.CreateConnectionOptions(String connectionString, DbConnectionOptions previous)\r\n at System.Data.ProviderBase.DbConnectionFactory.GetConnectionPoolGroup(DbConnectionPoolKey key, DbConnectionPoolGroupOptions poolOptions, DbConnectionOptions& userConnectionOptions)\r\n at System.Data.SqlClient.SqlConnection.ConnectionString_Set(DbConnectionPoolKey key)\r\n at System.Data.SqlClient.SqlConnection.set_ConnectionString(String value)\r\n at System.Data.SqlClient.SqlConnection..ctor(String connectionString, SqlCredential credential)\r\n at System.Data.SqlClient.SqlConnection..ctor(String connectionString)\r\n at Simple.Data.SqlServer.SqlConnectionProvider.CreateConnection()\r\n at Simple.Data.SqlServer.SqlSchemaProvider.GetSchema(String collectionName, String[] constraints)\r\n at Simple.Data.SqlServer.SqlSchemaProvider.GetStoredProcedures()\r\n at Simple.Data.Ado.Schema.DatabaseSchema.CreateProcedureCollection()\r\n at System.Lazy1.CreateValue()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()\r\n at System.Lazy1.get_Value()\r\n at Simple.Data.Ado.Schema.DatabaseSchema.IsProcedure(String procedureName)\r\n at Simple.Data.Ado.AdoAdapter.IsValidFunction(String functionName)\r\n at Simple.Data.DataStrategy.TryInvokeFunction(String functionName, Func1 getFunctionArguments, Object& result)\r\n at Simple.Data.DataStrategy.TryInvokeMember(InvokeMemberBinder binder, Object[] args, Object& result)\r\n at CallSite.Target(Closure , CallSite , Object )\r\n at System.Dynamic.UpdateDelegates.UpdateAndExecute1[T0,TRet](CallSite site, T0 arg0)\r\n at Invoker(CallSiteBinder , Object , Object[] )\r\n at Microsoft.VisualBasic.CompilerServices.IDOUtils.CreateRefCallSiteAndInvoke(CallSiteBinder Action, Object Instance, Object[] Arguments)\r\n at Microsoft.VisualBasic.CompilerServices.IDOBinder.IDOGet(IDynamicMetaObjectProvider Instance, String MemberName, Object[] Arguments, String[] ArgumentNames, Boolean[] CopyBack)\r\n at Microsoft.VisualBasic.CompilerServices.NewLateBinding.LateGet(Object Instance, Type Type, String MemberName, Object[] Arguments, String[] ArgumentNames, Type[] TypeArguments, Boolean[] CopyBack)\r\n at DynamicAPI.Controllers.IOsController.VB$StateMachine_3_DeleteValue.MoveNext() in d:\\Doc\\Visual Studio 2013\\Projects\\DynamicAPI\\DynamicAPI\\Controllers\\IOsController.vb:line 151\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()\r\n at System.Threading.Tasks.TaskHelpersExtensions.d__31.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()\r\n at System.Web.Http.Controllers.ApiControllerActionInvoker.d__0.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()\r\n at System.Web.Http.Controllers.ActionFilterResult.<ExecuteAsync>d__2.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter1.GetResult()\r\n at System.Web.Http.Dispatcher.HttpControllerDispatcher.d__1.MoveNext()"
}

@WayneHiller
Copy link

Could it be a permissions error or maybe the delete is generating an error?

@johnsev
Copy link
Author

johnsev commented Feb 14, 2016

I logged in with SSMS using those same credentials to confirm I can delete the record in question. I also verified the stored proc worked before trying to use it with Simple.Data.

John

On Feb 13, 2016, at 11:29 AM, WayneHiller <[email protected]mailto:[email protected]> wrote:

Could it be a permissions error or maybe the delete is generating an error?

Reply to this email directly or view it on GitHubhttps://github.com//issues/383#issuecomment-183707250.

@rippo
Copy link

rippo commented Feb 15, 2016

Can you delete the record using vanilla ado.net c# and the same connection string?

@johnsev
Copy link
Author

johnsev commented Feb 15, 2016

I'll give that a try however, I am working in VB.nethttp://vb.net.

John

On Feb 15, 2016, at 2:08 AM, Richard Wilde <[email protected]mailto:[email protected]> wrote:

Can you delete the record using vanilla ado.nethttp://ado.net c# and the same connection string?

Reply to this email directly or view it on GitHubhttps://github.com//issues/383#issuecomment-184106290.

@johnsev
Copy link
Author

johnsev commented Feb 19, 2016

It works in ADO.net. Here is my code. It is an action in a WebAPI written in VB.net.

`
Public Async Function DeleteValue(ByVal dbName As String, ByVal id As Integer) As Task(Of IHttpActionResult)
Await Task.Yield
Dim db As Object
Try

            //This does not work
            db = Database.OpenConnection(dbName)
            db.IO.DeleteByID(id)

            //This works
            Using conn As SqlConnection = New SqlConnection(ConfigurationManager.ConnectionStrings(dbName).ConnectionString)
                Using cmd As SqlCommand = New SqlCommand("DELETE IO WHERE ID = " & id)
                    cmd.Connection = conn
                    conn.Open()
                    cmd.ExecuteNonQuery()
                    conn.Close()
                End Using
            End Using

            Return StatusCode(HttpStatusCode.Accepted)
        Catch ex As Exception
            If IsNothing(db) Then
                Throw
                //todo: error hanlder for bad db connection
            Else
                Throw
                //todo: Error Handlers for a delete failure
            End If
        End Try
    End Function

`

@johnsev
Copy link
Author

johnsev commented Feb 19, 2016

Not sure why the first few lines of code are not formatted as code in my previous post. I thought it was perhaps the apostrophe used as a comment in VB.net so I changed it to // even though it is not syntactially correct in VB.

@BenMagyar
Copy link

There dbName is the name of your connection. Database.OpenConnection expects a connectionString not so much the named configuration value. To open by a connectionName you should be using Database.OpenNamedConnection instead which does what you are looking for.

Using Database.OpenConnection throws the Format of the initialization string does not conform to specification starting at index 0. exception because the dbName value is not a well-formed connectionString.

@johnsev
Copy link
Author

johnsev commented Feb 20, 2016

Ugh! I'm a bonehead. I've been looking at this code too long and just looked over that. Everywhere else in my code I use OpenNamedConnection except for here. Also, because it only errored when I tried the delete statement and not on OpenConnection(dbName) I just assumed that the connection was good. I guess it doesn't try making the connection until some work needs to be done.

Sorry for spinning you up over nothing and thanks for your help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants