2011-12-26 74 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