Re: Web Service + SqlConnection

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



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

}



.



Relevant Pages

  • Re: need help with connect string
    ... Dim Conn As New SqlConnection("Data ... The mydb.mdf is not in the usual Sql server data ... It sounds as if the database was created as part of a user instance. ...
    (microsoft.public.data.oledb)
  • Re: OleDbParameter vs. manually SQL Statement to Insert mass date from host
    ... But I think a bulkcopy is a "external" Database tool, ... Hitchhiker's Guide to Visual Studio and SQL Server ... and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook) ... conn = new OleDbConnection; ...
    (microsoft.public.dotnet.framework.adonet)
  • Re: Web Service + SqlConnection
    ... Do I do that from Visual Studio or from MS SQL Server 2005? ... Now I've added an SQL Database object Database.mdf into my project. ... Subsequent publishing, however, results in the same message. ... tabljic", conn); ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: No db access after publishing web site
    ... In there is only App_Data folder ASPNETDB.MDF ... Are you detaching/attaching the SQL Server Express database correctly? ... the instructions I found in Visual studio help Walkthrough: Publishing ...
    (microsoft.public.dotnet.framework.aspnet)
  • Re: No db access after publishing web site
    ... Cannot open database "pago" requested by the login. ... Are you detaching/attaching the SQL Server Express database correctly? ... the instructions I found in Visual studio help Walkthrough: Publishing ...
    (microsoft.public.dotnet.framework.aspnet)