2016-11-23 23 views
0

被激活,我在一個典型的應用WPF使用本地數據庫。我試圖運行調試,但它沒有工作,給了我以下錯誤:
Sql Service
了SQL-Server服務在本地應用

<2016-11-23T17:59:19.1888435+03:30 The underlying provider failed on Open. 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.ObjectContext.<>c__DisplayClass47 1.<ExecuteFunction>b__45() at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func 1 operation) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, ExecutionOptions executionOptions, ObjectParameter[] parameters) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, MergeOption mergeOption, ObjectParameter[] parameters) at System.Data.Entity.Core.Objects.ObjectContext.ExecuteFunction[TElement](String functionName, ObjectParameter[] parameters) at FirstAttemptForFillingOutTheContent.EngineEntities.SignIn(String mail, String password) in c:\Users\Media Depp\Documents\Visual Studio 2013\NewProjects\SeyyedAmir\FirstAttemptForFillingOutTheContent\FirstAttemptForFillingOutTheContent\EngineModel.Context.cs:line 61 at FirstAttemptForFillingOutTheContent.DataAccess.SearchUSerDA(String name, String pass) in c:\Users\Media Depp\Documents\Visual Studio 2013\NewProjects\SeyyedAmir\FirstAttemptForFillingOutTheContent\FirstAttemptForFillingOutTheContent\DataAccess.cs:line 140 EntityFramework 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: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)


搜索我想通了,我OS的數據庫服務處於非活動狀態後
我手動啓動它和程序工作正常。如果服務未激活,我如何在C#代碼本身中激活服務。我看起來像this職位,但我需要一些C#代碼來做到這一點。

+0

看來你的sqlserver託管在本地機器上,有時服務可能無法啓動,由於像自動啓動的設置,不是enabled.some次你的筆記本電腦可能會重新啓動多次,我沒有看到一次SQL任何問題託管 – TheGameiswar

+0

@TheGameiswar是的,有時服務不會自動啓動,在這種情況下,我的應用程序不能正常工作。我想從我自己的應用程序開始。我不明白你不明白哪一部分 – Media

回答

1

您可以使用命令行提示符,並使用以下命令:

NET START MSSQLSERVER啓動SQL Server作爲一種服務。

NET START MSSQL$instancename啓動SQL Server作爲一種服務,其中instancename是數據庫服務器實例的實際名稱。

兩種方式在C#:

var sc = new System.ServiceProcess.ServiceController("MyService", "MyRemoteMachine"); 
sc.Start(); 
sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Running); 
sc.Stop(); 
sc.WaitForStatus(System.ServiceProcess.ServiceControllerStatus.Stopped); 

sc <server> start [service name] 
sc <server> stop [service name] 

使用sc <server> query | find "SERVICE_NAME"

獲得服務名稱的列表。

選項<server>具有形式\\ServerName

sc \\MyServer stop schedule將停止調度程序服務。

+0

你能告訴我在C#中如何做到這一點嗎? – Media

+0

已添加到答覆。 – bwilliamson

相關問題