Saltar al contenido principal

 none
Error DataFill Local Db C# RRS feed

  • Pregunta

  • Hola tengo este connection string para conectarme a una base de datos localDb desde MSSS me puedo conectar normal pero cuando trato de ejecutar este codigo me sale el siguiente error:

    string cs = @"Data Source=(LocalDB)\SQLPRINTERBI;AttachDbFilename=C:\ProgramData\SQLPrinterBI\DATA\SQLPrinterBI.mdf;Integrated Security=True";

    Este es el codigo que utilizo para ejecutar un Stored Procedure y traer como resultado un dataset.

                             

    using (SqlConnection conn = new SqlConnection(cs))
                    {
                        SqlCommand sqlComm = new SqlCommand(procname, conn);
                        for (int i = 0; i <= parmname.Count - 1; i++)
                        {

                            sqlComm.Parameters.AddWithValue("@" + parmname[i].Split(',')[0], parmname[i].Split(',')[1]);
                        }
                        sqlComm.CommandType = CommandType.StoredProcedure;
                        SqlDataAdapter da = new SqlDataAdapter();
                        da.SelectCommand = sqlComm;
                        da.Fill(ds);

                    }
                }

    y este es el error:

    System.Data.SqlClient.SqlException (0x80131904): Error relacionado con la red o específico de la instancia mientras se establecía una conexión con el servidor SQL Server. No se encontró el servidor o éste no estaba accesible. Compruebe que el nombre de la instancia es correcto y que SQL Server está configurado para admitir conexiones remotas. (provider: SQL Network Interfaces, error: 50 - Se produjo un error de Local Database Runtime. La instancia de LocalDB especificada no existe.
    )
       en System.Data.SqlClient.SqlInternalConnectionTds..ctor(DbConnectionPoolIdentity identity, SqlConnectionString connectionOptions, SqlCredential credential, Object providerInfo, String newPassword, SecureString newSecurePassword, Boolean redirectedUserInstance, SqlConnectionString userConnectionOptions, SessionData reconnectSessionData, DbConnectionPool pool, String accessToken, Boolean applyTransientFaultHandling, SqlAuthenticationProviderManager sqlAuthProviderManager)
       en System.Data.SqlClient.SqlConnectionFactory.CreateConnection(DbConnectionOptions options, DbConnectionPoolKey poolKey, Object poolGroupProviderInfo, DbConnectionPool pool, DbConnection owningConnection, DbConnectionOptions userOptions)
       en System.Data.ProviderBase.DbConnectionFactory.CreatePooledConnection(DbConnectionPool pool, DbConnection owningObject, DbConnectionOptions options, DbConnectionPoolKey poolKey, DbConnectionOptions userOptions)
       en System.Data.ProviderBase.DbConnectionPool.CreateObject(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       en System.Data.ProviderBase.DbConnectionPool.UserCreateRequest(DbConnection owningObject, DbConnectionOptions userOptions, DbConnectionInternal oldConnection)
       en System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, UInt32 waitForMultipleObjectsTimeout, Boolean allowCreate, Boolean onlyOneCheckConnection, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       en System.Data.ProviderBase.DbConnectionPool.TryGetConnection(DbConnection owningObject, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal& connection)
       en System.Data.ProviderBase.DbConnectionFactory.TryGetConnection(DbConnection owningConnection, TaskCompletionSource`1 retry, DbConnectionOptions userOptions, DbConnectionInternal oldConnection, DbConnectionInternal& connection)
       en System.Data.ProviderBase.DbConnectionInternal.TryOpenConnectionInternal(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       en System.Data.ProviderBase.DbConnectionClosed.TryOpenConnection(DbConnection outerConnection, DbConnectionFactory connectionFactory, TaskCompletionSource`1 retry, DbConnectionOptions userOptions)
       en System.Data.SqlClient.SqlConnection.TryOpenInner(TaskCompletionSource`1 retry)
       en System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
       en System.Data.SqlClient.SqlConnection.Open()
       en System.Data.Common.DbDataAdapter.FillInternal(DataSet dataset, DataTable[] datatables, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       en System.Data.Common.DbDataAdapter.Fill(DataSet dataSet, Int32 startRecord, Int32 maxRecords, String srcTable, IDbCommand command, CommandBehavior behavior)
       en System.Data.Common.DbDataAdapter.Fill(DataSet dataSet)
       en WindowsService.DynamicCallDB.calldb(String procname, List`1 parmname)
       en WindowsService.Service1.WorkProcess(Object sender, ElapsedEventArgs e)
    ClientConnectionId:00000000-0000-0000-0000-000000000000
    Error Number:-1983577849,State:0,Class:20

    Gracias por la ayuda

    martes, 29 de octubre de 2019 16:00