3

I developed a desktop application that uses local DB. It is running fine on my computer (which has sql server installed). But when i run it on another system (that doesn't has sql server) it shows following error message.

what process i have to follow that my published code work on clients computer

I am a new-bee with the technology, so please ask me if unclear.

EDIT: I am using the Following connection string

 <connectionStrings>
<add name="RestaurantManagerEntities" connectionString="metadata=res://*/Context.RestaurantManagerDbContext.csdl|res://*/Context.RestaurantManagerDbContext.ssdl|res://*/Context.RestaurantManagerDbContext.msl;provider=System.Data.SqlClient;provider connection string=&quot;data source=(LocalDB)\v11.0;attachdbfilename=|DataDirectory|\RestaurantManager.mdf;integrated security=True;MultipleActiveResultSets=True;App=EntityFramework&quot;" providerName="System.Data.EntityClient" />

See the end of this message for details on invoking 
just-in-time (JIT) debugging instead of this dialog box.

************** Exception Text **************
System.Data.Entity.Core.EntityException: The underlying provider failed on Open. ---> System.Data.SqlClient.SqlException: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: SQL Network Interfaces, error: 52 - Unable to locate a Local Database Runtime installation. Verify that SQL Server Express is properly installed and that the Local Database Runtime feature is enabled.) ---> System.ComponentModel.Win32Exception: The system cannot find the file specified
   --- End of inner exception stack trace ---
   at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction)
   at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose)
   at System.Data.SqlClient.TdsParser.Connect(ServerInfo serverInfo, SqlInternalConnectionTds connHandler, Boolean ignoreSniOpenTimeout, Int64 timerExpire, Boolean encrypt, Boolean trustServerCert, Boolean integratedSecurity, Boolean withFailover)
   at System.Data.SqlClient.SqlInternalConnectionTds.AttemptOneLogin(ServerInfo serverInfo, String newPassword, SecureString newSecurePassword, Boolean ignoreSniOpenTimeout, TimeoutTimer timeout, Boolean withFailover)
   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)
   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.TryOpenInner(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.TryOpen(TaskCompletionSource`1 retry)
   at System.Data.SqlClient.SqlConnection.Open()
   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.<Open>b__36(DbConnection t, DbConnectionInterceptionContext c)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext](TTarget target, Action`2 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbConnectionDispatcher.Open(DbConnection connection, DbInterceptionContext interceptionContext)
   at System.Data.Entity.Core.EntityClient.EntityConnection.<Open>b__2()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.<>c__DisplayClass1.<Execute>b__0()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute(Action operation)
   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   --- End of inner exception stack trace ---

Server stack trace: 
   at System.Data.Entity.Core.EntityClient.EntityConnection.Open()
   at System.Data.Entity.Core.Objects.ObjectContext.EnsureConnection(Boolean shouldMonitorTransactions)
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Linq.Enumerable.SingleOrDefault[TSource](IEnumerable`1 source)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.<GetElementFunction>b__2[TResult](IEnumerable`1 sequence)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.ExecuteSingle[TResult](IEnumerable`1 query, Expression queryRoot)
   at System.Data.Entity.Core.Objects.ELinq.ObjectQueryProvider.System.Linq.IQueryProvider.Execute[TResult](Expression expression)
   at System.Data.Entity.Internal.Linq.DbQueryProvider.Execute[TResult](Expression expression)
   at System.Linq.Queryable.SingleOrDefault[TSource](IQueryable`1 source, Expression`1 predicate)
   at RestaurantManager.Desktop.Managers.UserManager.LoginUser(String UserName, String Password) in n:\RestaurantManager\RestaurantManager.Desktop\Managers\UserManager.cs:line 140
   at RestaurantManager.Desktop.Login.LoginUser(Object sender, WaitWindowEventArgs e) in n:\RestaurantManager\RestaurantManager.Desktop\Login.cs:line 29
   at Jacksonsoft.WaitWindowGUI.DoWork() in n:\RestaurantManager\RestaurantManager.Desktop\Util\WaitWindowGUI.cs:line 59
   at System.Runtime.Remoting.Messaging.StackBuilderSink._PrivateProcessMessage(IntPtr md, Object[] args, Object server, Object[]& outArgs)
   at System.Runtime.Remoting.Messaging.StackBuilderSink.AsyncProcessMessage(IMessage msg, IMessageSink replySink)

Exception rethrown at [0]: 
   at Jacksonsoft.WaitWindow.Show(EventHandler`1 workerMethod, String message, List`1 args) in n:\RestaurantManager\RestaurantManager.Desktop\Util\WaitWindow.cs:line 110
   at Jacksonsoft.WaitWindow.Show(EventHandler`1 workerMethod, String message) in n:\RestaurantManager\RestaurantManager.Desktop\Util\WaitWindow.cs:line 38
   at Jacksonsoft.WaitWindow.Show(EventHandler`1 workerMethod) in n:\RestaurantManager\RestaurantManager.Desktop\Util\WaitWindow.cs:line 27
   at RestaurantManager.Desktop.Login.btnLogin_Click(Object sender, EventArgs e) in n:\RestaurantManager\RestaurantManager.Desktop\Login.cs:line 42
   at System.Windows.Forms.Control.OnClick(EventArgs e)
   at System.Windows.Forms.Button.OnClick(EventArgs e)
   at System.Windows.Forms.Button.PerformClick()
   at System.Windows.Forms.Form.ProcessDialogKey(Keys keyData)
   at System.Windows.Forms.Control.ProcessDialogKey(Keys keyData)
   at System.Windows.Forms.TextBoxBase.ProcessDialogKey(Keys keyData)
   at System.Windows.Forms.Control.PreProcessMessage(Message& msg)
   at System.Windows.Forms.Control.PreProcessControlMessageInternal(Control target, Message& msg)
   at System.Windows.Forms.Application.ThreadContext.PreTranslateMessage(MSG& msg)
Deepak
  • 178
  • 1
  • 2
  • 14
  • Did you change the `connectionString` to match the new system DB connection? – adricadar Mar 28 '15 at 09:01
  • It seems that you are using LocalDb. In this case you need to deploy your application with the [binaries of LocalDB](https://msdn.microsoft.com/en-us/evalcenter/dn434042.aspx). Choose the version appropriate for your database file (You can't use lower versions) – Steve Mar 28 '15 at 09:11
  • 1
    @Steve can you elaborate how can i choose version, while deploying i am using dotnet version 4.5. When i install sql server express on client's system my application starts working. – Deepak Mar 28 '15 at 11:43

2 Answers2

0

You are using (LocalDB)\v11.0 on current system and it comes installed with Visual Studio, read this for more information. On other system didn't work because you don't have installed a version of SQL Server.

If you want the application to work on another system, you have to install a version of SQL Server on that system. And you have to change connectionString to match the new SQL Server installed..

Community
  • 1
  • 1
adricadar
  • 9,971
  • 5
  • 33
  • 46
  • but i don't want to install sql server express on the client's system. – Deepak Mar 28 '15 at 11:44
  • @Deepak you don't need to install on client's system sql server express, if you app is for multi user, you can make a **system to act as server** and the client's system will have `connectrionString` pointing to that **server system**. – adricadar Mar 28 '15 at 11:46
  • It is a desktop application and has individual database for particular system. – Deepak Mar 28 '15 at 12:07
  • @Deepak if this is the case and you want to use an sql database, you have to install a SQL Server version (Express or others version) on clients system. You have considered to use something else then sql server, like keeping data in xml files? – adricadar Mar 28 '15 at 12:15
0

LocalDB is a particular version of Sql Server Express that doesn't require a complex installation. It is just a single MSI file that you need to run on the client PC and your connection string should work as is.

Instead the MDF file that you distribute has been created by a particular version of Sql Server (IE 2008R2, 2012, 2014 ?). MDF file created by an higher version of Sql Server cannot be read by a lower version. So when you download LocalDB.MSI you should choose the appropriate version.

See this question where you could find more details about LocalDB explained by one of developers of that code.

To download SQL LocalDB (2104 version) you could check this link

Community
  • 1
  • 1
Steve
  • 213,761
  • 22
  • 232
  • 286