Re: Web Service + SqlConnection
- From: "Cor Ligthert [MVP]" <notmyfirstname@xxxxxxxxx>
- Date: Sun, 5 Nov 2006 15:55:53 +0100
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
<axel22@xxxxxxxxx> schreef in bericht
news:1162724748.818899.49240@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
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<string> nadiImena()
{
List<string> ls = new List<string>();
ls.Add("Zikino ime.");
using (SqlConnection conn = new
SqlConnection(serviceConfiguration.connectionString))
{
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;
}
}
.
- Follow-Ups:
- Re: Web Service + SqlConnection
- From: axel22
- Re: Web Service + SqlConnection
- References:
- Web Service + SqlConnection
- From: axel22
- Web Service + SqlConnection
- Prev by Date: Re: Formatting A String As Currency
- Next by Date: Re: Preemptible Parallel Processing
- Previous by thread: Web Service + SqlConnection
- Next by thread: Re: Web Service + SqlConnection
- Index(es):
Relevant Pages
|