I'm experiencing a strange problem that has me baffled. I created a
webservice with a webmethod that connects to a remote MS SQL Server.
It works fine when connecting to one server (running SQL Server 7).
But it can't connect to another server (running SQL Server 2000). The
SQLConnection.O pen() call results in a long pause, then the error
"could not connect to server". What's odd is that if I put the exact
same SQLConnection code into a new Windows application project it
works with either server.
What could be making the SQL connection fail when it's in a webservice
compared to a Windows app? And why only with the one server?
Any help would be greatly appreciated! 3 7920
Hi stephen
Just a note before hitting the issue , you should be using SqlConnection
with SQL server 2000 and an OleDbConnection with SQL server 7. ( I guess
you already have that , if not then try to have SqlConnection with the 2000
as this may be the problem )
Another thing you may be looking at is the credentials of the user that
access the database. If you are using windows authentication , then mostly
this is the source of the problem. You said the connection worked form
windows app but not from the service. The windows application by default
run under the credentials of the logged on user . whoever this is no the
default behavior of the service.
Normally windows services run under an account that has minimum privileges
on the system. Try to run the service under a user account that you are
logged on with , as this mostly is the cause of the problem. To do so open
the services window ( control panel ' Administered tools ' services .
right click your service and select properties , then select the logon tab
and choose this account ( you many need to enter the username and the
password ).. hope that helps
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC
Thanks for the reply Mohamed. I'm using SqlConnection with the SQL 2000
server. The login is a user defined on the SQL Server:
SqlConnection mySQLConnection = new SqlConnection() ;
mySQLConnection .ConnectionStri ng="data source=192.168. 30.44;
uid=rocky;pwd=r accoon;database =myDatabase";
mySQLConnection .Open();
This code works fine in the Windows app with either SQL Server 7 or
2000. It also works fine in the webservice app with one server, which
happens to be SQL Server 7. It does not work with the other server,
running SQL Server 2000. I can connect to either database using
Enterprise Manager.
I looked in the Services control panel and do not see my webservice
there. I'm a little confused by your suggestion -- I didn't think
webservices were the same as other services.
Still stuck :-/
-Stephen
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Hi Steve
ahaaa , sorry I thought your using windows service so all what I said about
how to make it run under your account would not valid . However, still
the source of the problem would be the same . either services ( web ,
windows ) work with a minimum privileges account . however it is a
different story if you you want to change that for the web service . if
you want to impersonate user with your web service ( so it would have
enough privileges to connect ) you would need to pass to its proxy class (
the one that you are using for reference from your application ) a
credentials object . if you want to pass the credentials of the user of the
application , you would pass the default credentials object . Take a look
at that snippet I once had
if(chkDefault.C hecked){
s.Credentials = System.Net.Cred entialCache.Def aultCredentials ;
}
else{
//WindowsImperson ationContext impersonatedUse r =
WindowsIdentity .GetCurrent().I mpersonate();
//System.Net.Netw orkCredential myCred1
=System.Net.Cre dentialCache.De faultCredential s;
System.Net.Netw orkCredential myCred = (System.Net.Net workCredential)
System.Net.Cred entialCache.Def aultCredentials ;//
System.Net.Netw orkCredential(t xtuserid.Text,t xtpassword.Text ,txtdomain.Text )
;
System.Net.Cred entialCache myCache = new System.Net.Cred entialCache();
myCache.Add(new Uri(s.Url), txttype.Text, myCred);
MessageBox.Show (WindowsIdentit y.GetCurrent(). Name);
MessageBox.Show (WindowsIdentit y.GetCurrent(). IsAnonymous.ToS tring());
MessageBox.Show (System.Threadi ng.Thread.Curre ntPrincipal.Ide ntity.IsAuthent i
cated.ToString( ));
s.Credentials = myCache;
}
You might need to read about the System.Net.Cred entialCache a bit on MSDN
Mohamed Mahfouz
MEA Developer Support Center
ITworx on behalf of Microsoft EMEA GTSC This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Donnie Darko |
last post by:
I'm trying to understand SqlConnection(), SqlCommand()
For example. I use SqlConnection() as a parameter when I create a new
SqlCommand. Then I open SqlConnection(), then I execute the SqlCommand().
At that point I cannot use SqlConnection() again. Unless I .Close() it and
then .Open it right?
Then what is 'connection pooling' ?
Can't I run multiple SqlCommand()s on the same SqlConnection() somehow ?
|
by: arran.pearce |
last post by:
Hi,
I am using .NET 2 (beta2) and are having problems with using a SqlConnection.
I have created a test application that opens a sql connections, gets some
basic data and then closes the connection.
When i run this application as the administrator it works fine. However if
i run the application as a standard user the application hangs indefinatly on
SqlConnection.Open().
|
by: The Coolest Dolphin |
last post by:
Hi all,
I have a question/problem concerning usage of my sqlconnection throughout my
program.
In my main form (frmMain) I defined an sqlconnection (I've set the
connection public so that I can open & close the connection from everywhere
in my app).
My main form is an mdi parent which contains several mdi-childs.
To open and close the sqlconnection in an mdi-child i use the following:
|
by: Bob |
last post by:
In our new .NET web applications, we try to limit the use of SqlConnection
to just one instance per page, even if there are multiple accesses to
various queries. The thinking behind is that this reduces the need to
getting and returning connections to the pool repeatedly if a page has
multiple calls to the DB, and each one manages its own connection. However,
this does requires more deliberate coding, like calling the...
|
by: Steve Richter |
last post by:
I really miss c++ ....
I have an SqlConnection object within my Web.UI.Page object. The
thinking is that the connection to the database server is opened once
when the page starts to do its thing, then when everything is rendered
down to the browser, and all references to the page object are ended,
the connection to the server can be closed.
First of all, are the SqlConnection Open and Close methods quick
performers and I dont need to...
| |
by: Alex |
last post by:
Hi! I have previously designed class that would read encrypted connection
from registry, create a connection object (sql, oracle, oledb...) and return
it to the calling class. I had to change this class to a webservice, but I
keep running into various problems. The latest one has to do with the fact
that it requires me to use XMLInclude or SoapInclude. I'm fairly new to
webservices so what I need is a small, clear sample how to create a...
|
by: axel22 |
last post by:
Ok here it goes.
1. I've created a new web service project in F:\c#\WebSites\ServisBaze.
2. I've published the web service with IIS in a virtual directory who's
actual path is:
F:\c#\Published\ServisBaze
3. Tried opening it in a browser - it works perfectly.
4. Now I've added an SQL Database object Database.mdf into my project.
5. I've manually edited the database tables and added data.
6. I've added a webmethod 'izvadiImena' to work...
|
by: Victor |
last post by:
Hi Guys I have a problem here.
I want to improve the performance for a website. When I looked into the
system, I have found that the system made the "SqlConnection Object" static.
That mean only one SqlConnection object will be used.
Can someone tell me is that a correct way to do? Does that affect the system
performance?
Cheers
Victor
|
by: fniles |
last post by:
I am using VB.NET 2003. When using SQLClient.SQLConnection with SQL 2005
database,
1. connection pooling is automatically used, right ? I mean, in the
connection string I do not need to explicitly write Pooling=true ?
2. What is the default Max Pool size ? After I open the connection, how can
I check what is the max pool size ?
3. I always open the db right before I fill dataset or open a reader, then
close it right away, but sometimes I...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
| |
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: bsmnconsultancy |
last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...
| |