2011-12-26 72 views
1

我創建了訪問數據庫的web服務。數據庫和Web服務即SQL服務器和IIS都在同一臺計算機上。webservice訪問數據庫的問題

問題是,當我訪問web服務,然後使用我的客戶端訪問服務器上的數據庫時,一切工作正常。

但是,當我從其他電腦訪問它,我得到數據庫錯誤。

在訪問服務器時,相同的連接字符串ehich工作正常,但在遠程訪問web服務時未打開連接。

任何幫助表示讚賞。

[編輯]

當我訪問它的服務器上,我得到的日誌按我的要求是這樣的:

的ConnectionString =服務器=本地主機\實例;數據庫= DBNAME; UID = UID; PWD = PWD;

當我遠程訪問,我得到這樣的日誌:

的ConnectionString =服務器=本地主機\實例;數據庫= DBNAME; UID = UID; PWD = PWD;

錯誤:

System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> 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: 26 - Error Locating Server/Instance Specified) 
    at System.Web.Services.Protocols.SoapHttpClientProtocol.ReadResponse(SoapClientMessage message, WebResponse response, Stream responseStream, Boolean asyncCall) 
    at System.Web.Services.Protocols.SoapHttpClientProtocol.Invoke(String methodName, Object[] parameters) 
    at CMACLBilling.AuthenticationService.Service1.GetUser(String userName) 
    at CMACLBilling.BusinessControllers.UserBusinessController.Authenticate(String userName, String password, Int32& errorCode) 
    at CMACLBilling.LoginWindow.btnLogin_Click(Object sender, RoutedEventArgs e) 
    at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
    at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
    at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) 
    at System.Windows.UIElement.RaiseEvent(RoutedEventArgs e) 
    at System.Windows.Controls.Primitives.ButtonBase.OnClick() 
    at System.Windows.Controls.Button.OnClick() 
    at System.Windows.Controls.Primitives.ButtonBase.OnMouseLeftButtonUp(MouseButtonEventArgs e) 
    at System.Windows.UIElement.OnMouseLeftButtonUpThunk(Object sender, MouseButtonEventArgs e) 
    at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) 
    at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
    at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
    at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
    at System.Windows.UIElement.ReRaiseEventAs(DependencyObject sender, RoutedEventArgs args, RoutedEvent newEvent) 
    at System.Windows.UIElement.OnMouseUpThunk(Object sender, MouseButtonEventArgs e) 
    at System.Windows.Input.MouseButtonEventArgs.InvokeEventHandler(Delegate genericHandler, Object genericTarget) 
    at System.Windows.RoutedEventArgs.InvokeHandler(Delegate handler, Object target) 
    at System.Windows.RoutedEventHandlerInfo.InvokeHandler(Object target, RoutedEventArgs routedEventArgs) 
    at System.Windows.EventRoute.InvokeHandlersImpl(Object source, RoutedEventArgs args, Boolean reRaised) 
    at System.Windows.UIElement.RaiseEventImpl(DependencyObject sender, RoutedEventArgs args) 
    at System.Windows.UIElement.RaiseTrustedEvent(RoutedEventArgs args) 
    at System.Windows.UIElement.RaiseEvent(RoutedEventArgs args, Boolean trusted) 
    at System.Windows.Input.InputManager.ProcessStagingArea() 
    at System.Windows.Input.InputManager.ProcessInput(InputEventArgs input) 
    at System.Windows.Input.InputProviderSite.ReportInput(InputReport inputReport) 
    at System.Windows.Interop.HwndMouseInputProvider.ReportInput(IntPtr hwnd, InputMode mode, Int32 timestamp, RawMouseActions actions, Int32 x, Int32 y, Int32 wheel) 
    at System.Windows.Interop.HwndMouseInputProvider.FilterMessage(IntPtr hwnd, WindowMessage msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at System.Windows.Interop.HwndSource.InputFilterMessage(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at MS.Win32.HwndWrapper.WndProc(IntPtr hwnd, Int32 msg, IntPtr wParam, IntPtr lParam, Boolean& handled) 
    at MS.Win32.HwndSubclass.DispatcherCallbackOperation(Object o) 
    at System.Windows.Threading.ExceptionWrapper.InternalRealCall(Delegate callback, Object args, Int32 numArgs) 
    at MS.Internal.Threading.ExceptionFilterHelper.TryCatchWhen(Object source, Delegate method, Object args, Int32 numArgs, Delegate catchHandler) 
+0

指定有關連接字符串,如果你認爲它可能會導致問題或顯示的代碼錯誤.. – 2011-12-26 08:12:31

+0

@NiranjanKalas:我編輯了帖子 – Sandeep 2011-12-26 08:24:25

回答

1

正如我猜測你的連接,你是提供錯誤信息:

檢查您的連接字符串:

ConnectionString = "Server=localhost\instancename;Database=dbname;Uid=uid;Pwd=pwd;" 

,誤差Error Locating Server/Instance Specified - 網絡在建立與SQL Server的連接時發生相關或實例特定的錯誤。服務器未找到或無法訪問。

localhost是指您正在其中工作的系統。如果您從另一臺計算機訪問它,則會導致錯誤。

示例如下幫助配置正確的連接字符串:

<connectionStrings> 

<add name=」SampleConnectionString」 connectionString=」Data Source=machinename\instancename;Initial Catalog=AdventureWorks;Integrated Security=SSPI;Min Pool Size=5;Max Pool Size=60;Connect Timeout=30″ providerName=」System.Data.SqlClient」/> 

</connectionStrings> 

Connect via an IP address of your server

Server=190.190.200.100,1433;Network Library=DBMSSOCN;Initial Catalog=myDataBase;User ID=myUsername;Password=myPassword;

Server=IISPCNameServer= IISPCName\InstanceName

當我做了這樣的功能,你做複製comp從我的電腦屬性,然後實例名稱子宮名稱。

檢查以下鏈接解決這種類型的問題:
Resolving 「A network-related or instance-specific error occurred while establishing a connection to SQL Server…」

注: 你要檢查的SQL Server遠程訪問設置,如果上述連接不起作用。檢查下面的鏈接,使其工作:
How to configure SQL Server 2005 to allow remote connections
Remote Access Settings for SQL Server

連接字符串參考:
Connection strings for SQL Server 2008

+0

我曾經使用localhost,因爲IIS和SQL服務器將始終保持在同一臺機器上;數據庫正在被web服務訪問,本地主機是否工作? – Sandeep 2011-12-26 10:27:49

+0

嘗試使用Windows身份驗證'connectionString =「Initial Catalog = MyDb; Data Source = MyServer; Integrated Security = SSPI;」' – 2011-12-26 11:12:02