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;
}
}
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;
}
}
Comment