473,382 Members | 1,409 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,382 software developers and data experts.

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:\...\ServisBaze\, 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:\...\ServisBaze\, 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.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
private class serviceConfiguration
{
public static string connectionString
{
get
{
return
ConfigurationManager.AppSettings["connectionString"];
}
}
}

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

[WebMethod]
public List<stringnadiImena()
{
List<stringls = new List<string>();
ls.Add("Zikino ime.");
using (SqlConnection conn = new
SqlConnection(serviceConfiguration.connectionStrin g))
{
try
{
conn.Open();
SqlCommand com = new SqlCommand("SELECT * FROM
tabljic", conn);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
ls.Add((string)reader["ime"]);
}
}
catch (Exception e)
{
ls.Add(e.ToString());
}
finally
{
if (conn != null) conn.Close();
}
}
return ls;
}

}

Nov 5 '06 #1
2 5435
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 connectionstrings
http://www.connectionstrings.com/

I hope this helps,

Cor


<ax****@gmail.comschreef in bericht
news:11*********************@b28g2000cwb.googlegro ups.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:\...\ServisBaze\, 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:\...\ServisBaze\, 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.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
private class serviceConfiguration
{
public static string connectionString
{
get
{
return
ConfigurationManager.AppSettings["connectionString"];
}
}
}

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

[WebMethod]
public List<stringnadiImena()
{
List<stringls = new List<string>();
ls.Add("Zikino ime.");
using (SqlConnection conn = new
SqlConnection(serviceConfiguration.connectionStrin g))
{
try
{
conn.Open();
SqlCommand com = new SqlCommand("SELECT * FROM
tabljic", conn);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
ls.Add((string)reader["ime"]);
}
}
catch (Exception e)
{
ls.Add(e.ToString());
}
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 connectionstrings
http://www.connectionstrings.com/

I hope this helps,

Cor


<ax****@gmail.comschreef in bericht
news:11*********************@b28g2000cwb.googlegro ups.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:\...\ServisBaze\, 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:\...\ServisBaze\, 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.Services;
using System.Web.Services.Protocols;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;

[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
public class Service : System.Web.Services.WebService
{
private class serviceConfiguration
{
public static string connectionString
{
get
{
return
ConfigurationManager.AppSettings["connectionString"];
}
}
}

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

[WebMethod]
public List<stringnadiImena()
{
List<stringls = new List<string>();
ls.Add("Zikino ime.");
using (SqlConnection conn = new
SqlConnection(serviceConfiguration.connectionStrin g))
{
try
{
conn.Open();
SqlCommand com = new SqlCommand("SELECT * FROM
tabljic", conn);
SqlDataReader reader = com.ExecuteReader();
while (reader.Read())
{
ls.Add((string)reader["ime"]);
}
}
catch (Exception e)
{
ls.Add(e.ToString());
}
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
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...
2
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...
2
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
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...
8
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...
1
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...
5
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...
3
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...
2
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.