473,609 Members | 1,831 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Web Service + SqlConnection

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 with the database.
7. I've published the website - it works like a charm.
8. Now I've changed the source code a little bit, and tried publishing
it again. I get an error:

------ Build started: Project: F:\...\ServisBa ze\, Configuration: Debug
..NET ------
Pre-compiling Web Site

Building directory '/ServisBaze/App_Code/'./: Publication (web): The
process cannot access the file
'F:\c#\WebSites \ServisBaze\App _Data\Database. mdf' because it is being
used by another process.

Pre-compilation Complete
------ Skipped Publish: Project F:\...\ServisBa ze\, Configuration:
Debug .NET ------

========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped
==========
========== Publish: 0 succeeded, 0 failed, 1 skipped ==========

9. I bang my head against the wall.
10. As write this post down, and some time has passed, I try to publish
it again, and it works.
Subsequent publishing, however, results in the same message.
<br>
<br>

Could anyone explain? Could it be that a connection pool has been
created and
it denies subsequent access to database?
Does anybody know how I can prevent this from happening, so I don't
have to
wait 5 minutes each time I change something in the source code.

<br>
<br>

Here is my source code:

using System;
using System.Web;
using System.Web.Serv ices;
using System.Web.Serv ices.Protocols;
using System.Collecti ons.Generic;
using System.Configur ation;
using System.Data.Sql Client;

[WebService(Name space = "http://tempuri.org/")]
[WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
public class Service : System.Web.Serv ices.WebService
{
private class serviceConfigur ation
{
public static string connectionStrin g
{
get
{
return
ConfigurationMa nager.AppSettin gs["connectionStri ng"];
}
}
}

public Service () {
//Uncomment the following line if using designed components
//InitializeCompo nent();
}

[WebMethod]
public List<stringnadi Imena()
{
List<stringls = new List<string>();
ls.Add("Zikino ime.");
using (SqlConnection conn = new
SqlConnection(s erviceConfigura tion.connection String))
{
try
{
conn.Open();
SqlCommand com = new SqlCommand("SEL ECT * FROM
tabljic", conn);
SqlDataReader reader = com.ExecuteRead er();
while (reader.Read())
{
ls.Add((string) reader["ime"]);
}
}
catch (Exception e)
{
ls.Add(e.ToStri ng());
}
finally
{
if (conn != null) conn.Close();
}
}
return ls;
}

}

Nov 5 '06 #1
2 5448
Axel,

Try to get the SQL server on its IP address instead of the drive and don't
use integrated securitiy.
(First you have to "attach" really of course the database to your SQL server
and don't use the SQLExpress testing method).

Here the page with connectionstrin gs
http://www.connectionstrings.com/

I hope this helps,

Cor


<ax****@gmail.c omschreef in bericht
news:11******** *************@b 28g2000cwb.goog legroups.com...
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 with the database.
7. I've published the website - it works like a charm.
8. Now I've changed the source code a little bit, and tried publishing
it again. I get an error:

------ Build started: Project: F:\...\ServisBa ze\, Configuration: Debug
.NET ------
Pre-compiling Web Site

Building directory '/ServisBaze/App_Code/'./: Publication (web): The
process cannot access the file
'F:\c#\WebSites \ServisBaze\App _Data\Database. mdf' because it is being
used by another process.

Pre-compilation Complete
------ Skipped Publish: Project F:\...\ServisBa ze\, Configuration:
Debug .NET ------

========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped
==========
========== Publish: 0 succeeded, 0 failed, 1 skipped ==========

9. I bang my head against the wall.
10. As write this post down, and some time has passed, I try to publish
it again, and it works.
Subsequent publishing, however, results in the same message.
<br>
<br>

Could anyone explain? Could it be that a connection pool has been
created and
it denies subsequent access to database?
Does anybody know how I can prevent this from happening, so I don't
have to
wait 5 minutes each time I change something in the source code.

<br>
<br>

Here is my source code:

using System;
using System.Web;
using System.Web.Serv ices;
using System.Web.Serv ices.Protocols;
using System.Collecti ons.Generic;
using System.Configur ation;
using System.Data.Sql Client;

[WebService(Name space = "http://tempuri.org/")]
[WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
public class Service : System.Web.Serv ices.WebService
{
private class serviceConfigur ation
{
public static string connectionStrin g
{
get
{
return
ConfigurationMa nager.AppSettin gs["connectionStri ng"];
}
}
}

public Service () {
//Uncomment the following line if using designed components
//InitializeCompo nent();
}

[WebMethod]
public List<stringnadi Imena()
{
List<stringls = new List<string>();
ls.Add("Zikino ime.");
using (SqlConnection conn = new
SqlConnection(s erviceConfigura tion.connection String))
{
try
{
conn.Open();
SqlCommand com = new SqlCommand("SEL ECT * FROM
tabljic", conn);
SqlDataReader reader = com.ExecuteRead er();
while (reader.Read())
{
ls.Add((string) reader["ime"]);
}
}
catch (Exception e)
{
ls.Add(e.ToStri ng());
}
finally
{
if (conn != null) conn.Close();
}
}
return ls;
}

}

Nov 5 '06 #2
Do I do that from Visual Studio or from MS SQL Server 2005?
I can only see that it is a service from the Configuration Manager,
but I'll look this up.
Thnx!

Cor Ligthert [MVP] je napisao/la:
Axel,

Try to get the SQL server on its IP address instead of the drive and don't
use integrated securitiy.
(First you have to "attach" really of course the database to your SQL server
and don't use the SQLExpress testing method).

Here the page with connectionstrin gs
http://www.connectionstrings.com/

I hope this helps,

Cor


<ax****@gmail.c omschreef in bericht
news:11******** *************@b 28g2000cwb.goog legroups.com...
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 with the database.
7. I've published the website - it works like a charm.
8. Now I've changed the source code a little bit, and tried publishing
it again. I get an error:

------ Build started: Project: F:\...\ServisBa ze\, Configuration: Debug
.NET ------
Pre-compiling Web Site

Building directory '/ServisBaze/App_Code/'./: Publication (web): The
process cannot access the file
'F:\c#\WebSites \ServisBaze\App _Data\Database. mdf' because it is being
used by another process.

Pre-compilation Complete
------ Skipped Publish: Project F:\...\ServisBa ze\, Configuration:
Debug .NET ------

========== Build: 0 succeeded or up-to-date, 1 failed, 0 skipped
==========
========== Publish: 0 succeeded, 0 failed, 1 skipped ==========

9. I bang my head against the wall.
10. As write this post down, and some time has passed, I try to publish
it again, and it works.
Subsequent publishing, however, results in the same message.
<br>
<br>

Could anyone explain? Could it be that a connection pool has been
created and
it denies subsequent access to database?
Does anybody know how I can prevent this from happening, so I don't
have to
wait 5 minutes each time I change something in the source code.

<br>
<br>

Here is my source code:

using System;
using System.Web;
using System.Web.Serv ices;
using System.Web.Serv ices.Protocols;
using System.Collecti ons.Generic;
using System.Configur ation;
using System.Data.Sql Client;

[WebService(Name space = "http://tempuri.org/")]
[WebServiceBindi ng(ConformsTo = WsiProfiles.Bas icProfile1_1)]
public class Service : System.Web.Serv ices.WebService
{
private class serviceConfigur ation
{
public static string connectionStrin g
{
get
{
return
ConfigurationMa nager.AppSettin gs["connectionStri ng"];
}
}
}

public Service () {
//Uncomment the following line if using designed components
//InitializeCompo nent();
}

[WebMethod]
public List<stringnadi Imena()
{
List<stringls = new List<string>();
ls.Add("Zikino ime.");
using (SqlConnection conn = new
SqlConnection(s erviceConfigura tion.connection String))
{
try
{
conn.Open();
SqlCommand com = new SqlCommand("SEL ECT * FROM
tabljic", conn);
SqlDataReader reader = com.ExecuteRead er();
while (reader.Read())
{
ls.Add((string) reader["ime"]);
}
}
catch (Exception e)
{
ls.Add(e.ToStri ng());
}
finally
{
if (conn != null) conn.Close();
}
}
return ls;
}

}
Nov 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
7915
by: Stephen | last post by:
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.Open() 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...
2
7154
by: hazz | last post by:
I don't get it. I have a VS2005 solution with a web service project and a windows project. The web service when tested on its own works fine. But when I add it as a web reference and refer to it my windows form code behind I receive the following; {"The request failed with HTTP status 401: Unauthorized."} when trying to execute this.dataGridView1.DataSource = ws.ReturnStudentDS(); not sure if it is relevant but the web.config in the...
2
1250
by: Michael Rodriguez | last post by:
Is this possible? I tried but it complains about the SqlConnection not being fully serializable. Are there any workarounds for this? TIA, Mike Rodriguez
10
1896
by: amirmira | last post by:
I have a Windows Service developed in VB.NET that attempts to connect to a database as soon as the service starts. I have no problem when I start the service manually - but when I restart the computer that hosts the service, I get a Null Reference Exception when I try to connect to the database (I have set the service to start automatically). Any ideas why this is happening? Thanks in advance. Ajay Mirmira
8
7599
by: nautonnier | last post by:
I know my problem has been discussed ad nauseum but I still don't get it so please bear with me. I have written a service which performs some work against a database once a day (usually in the wee hours of the morning). From the time the service starts to the first time it hits the database its memory consumption is about 6.9MB which is a figure I can live with. However, after it hits the database for the first time its memory jumps to...
1
5963
by: TOLI | last post by:
Where do a set the right user rights for ASP.NET 2 to connect to a SQL service Se below // Exception Details: System.Data.SqlClient.SqlException: Login failed for user 'NT AUTHORITY\NETWORK SERVICE'. Source Error: An unhandled exception was generated during the execution of the current web
5
4252
by: sonali_reddy123 | last post by:
Hello all, I am trying to develop an application which will run as a windows service. The application should have Normal options available with service like start, stop and pause but along with this I need an option to show the windows application which my service has started as a result of its invokation. So I have written a service control by adding a new project of type
3
1573
by: naveen babu | last post by:
hi, i have built a window service to send an email alert.. when i start the service..i get the following msg The ScheduleAlert service on Local Computer started and then stopped. Some services stop automatically if they have no work to do, for example the Performance Logs and Alerts service. when i check my event log i have teh following error msg
2
3233
by: shauncl | last post by:
Hello Everyone, I'm currently writing a simple Windows Service (C#) that pings an ip address and inserts the pingreply result in a SQL table. I'm able to send a ping request and get the reply status but I have yet to figure out how to get the sql insert to work. The funny thing is, I'm able to ping and insert through a console application but not a Windows Service. I think it might have something to do with my Account information but my...
0
8139
marktang
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...
0
8091
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,...
0
8555
jinu1996
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...
1
8232
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,...
1
6064
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5524
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();...
0
4032
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2540
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1686
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.