System.DllNotFoundException: Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)

Hello guys. So im trying to run a invoke code with ‘sqlclient.sqlbulkcopy’ that looks like this:

Using connection As New System.Data.SqlClient.SqlConnection(connectionString)
    connection.Open()
    Using bulkCopy As New System.Data.SqlClient.SqlBulkCopy(connection)
        bulkCopy.DestinationTableName = tableName

        Try
            bulkCopy.BulkCopyTimeout = 60 
            bulkCopy.WriteToServer(dataTable)
        Catch ex As Exception
            out_ExceptionMessage = ex.Message 
            Throw
        End Try
    End Using
End Using

But i keep getting an error, that looks like this: System.DllNotFoundException: Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
What could be the problem here?

@Povilas_Jonikas,

Check if this works for you.

Thanks,
Ashok :slight_smile:

1 Like

Thanks for the response @ashokkarale ,
But i still dont get it. So the main reason why I get theese errors, because I have used database activities earlier?

@Povilas_Jonikas,

Where exactly Studio pointing this error? Which activity or compile time?

When i use Invoke code to bulk insert into database

@Povilas_Jonikas ,

ok. Have you tried to search and add for the missing dll in imports of the workflow?

1 Like

Actually, no, i have no idea how the import package should look like :smiley:

@Povilas_Jonikas,

It would be at bottom of your workflow.

1 Like

Yes, i know where the imports are, but what should be the namespace for the import? because i cant find nothing like “System.DLL” or something like that
Thanks

@Povilas_Jonikas,

Try importing SQL related one.

image

1 Like

Yeah, so i imported it, but still get the same error:

System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.TdsParser' threw an exception. ---> System.TypeInitializationException: The type initializer for 'System.Data.SqlClient.SNILoadHandle' threw an exception. ---> System.DllNotFoundException: Unable to load DLL 'sni.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)   at System.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize(IntPtr pmo)
   at System.Data.SqlClient.SNINativeMethodWrapper.SNIInitialize()
   at System.Data.SqlClient.SNILoadHandle..ctor()
   at System.Data.SqlClient.SNILoadHandle..cctor()
	--- End of inner exception stack trace ---
   at System.Data.SqlClient.TdsParserStateObjectFactory.get_EncryptionOptions()
   at System.Data.SqlClient.TdsParser..cctor()
	--- End of inner exception stack trace ---
   at System.Data.SqlClient.TdsParser..ctor(Boolean MARS, Boolean fAsynchronous)
   at System.Data.SqlClient.SqlInternalConnectionTds.LoginNoFailover(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString connectionOptions, SqlCredential credential, TimeoutTimer timeout)
   at System.Data.SqlClient.SqlInternalConnectionTds.OpenLoginEnlist(TimeoutTimer timeout, SqlConnectionString connectionOptions, SqlCredential credential, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance)
   at System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, Boolean applyTransientFaultHandling, String accessToken)
   at System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
   at System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at UiPathCodeRunner_cd7933d64e4647efa93374d0631bf11e.Run(DataTable dataTable, String connectionString, String tableName, String& out_ExceptionMessage)
   at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor)
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
	--- End of inner exception stack trace ---
   at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span`1 copyOfArgs, BindingFlags invokeAttr)
   at System.Reflection.MethodBaseInvoker.InvokeWithFewArgs(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
   at System.RuntimeType.InvokeMember(String name, BindingFlags bindingFlags, Binder binder, Object target, Object[] providedArgs, ParameterModifier[] modifiers, CultureInfo culture, String[] namedParams)
   at UiPath.Core.Activities.InvokeCode.Execute(CodeActivityContext context)
   at System.Activities.CodeActivity.InternalExecute(ActivityInstance instance, ActivityExecutor executor, BookmarkManager bookmarkManager)
   at System.Activities.Runtime.ActivityExecutor.ExecuteActivityWorkItem.ExecuteBody(ActivityExecutor executor, BookmarkManager bookmarkManager, Location resultLocation)

@Povilas_Jonikas,

I’m not able to find it but recently there is change in using connection string for SQL connection. Some parameters we pass in sql connection string are changed.

I will try to find it but you also try searching it. I think this is the issue.

1 Like

Is it like that?:

Driver={};Server=;Database=;Uid=;Pwd=

@Povilas_Jonikas,

Sorry my bad it’s not connection string, it’s namespace got changed.

Try importing Microsoft.Data.SqlClient

Thanks,
Ashok :slightly_smiling_face:

1 Like

Thanks for the answer and sorry for the late response, but i still get the same error:

@Povilas_Jonikas,

May be we should be updating the code also like this?

Using connection As New Microsoft.Data.SqlClient.SqlConnection(connectionString)
    connection.Open()
    Using bulkCopy As New Microsoft.Data.SqlClient.SqlBulkCopy(connection)
        bulkCopy.DestinationTableName = tableName

        Try
            bulkCopy.BulkCopyTimeout = 60 
            bulkCopy.WriteToServer(dataTable)
        Catch ex As Exception
            out_ExceptionMessage = ex.Message 
            Throw
        End Try
    End Using
End Using

Thanks,
Ashok :slight_smile:

1 Like

Yes sir, your provided code fix has just worked. Thanks a lot man!

@Povilas_Jonikas,

Finally :v: Glad it worked :star_struck:

Thanks,
Ashok :slight_smile:

1 Like

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.