Web Service + SqlConnection

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • axel22@gmail.com

    #1

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

    }

  • Cor Ligthert [MVP]

    #2
    Re: Web Service + SqlConnection

    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
    All connection strings in one place. Find the syntax for your database connection using ADO.NET, ADO, ODBC, OLEDB, C#, VB, VB.NET, ASP.NET and more.


    I hope this helps,

    Cor




    <axel22@gmail.c omschreef in bericht
    news:1162724748 .818899.49240@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;
    }
    >
    }
    >

    Comment

    • axel22@gmail.com

      #3
      Re: Web Service + SqlConnection

      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
      All connection strings in one place. Find the syntax for your database connection using ADO.NET, ADO, ODBC, OLEDB, C#, VB, VB.NET, ASP.NET and more.

      >
      I hope this helps,
      >
      Cor
      >
      >
      >
      >
      <axel22@gmail.c omschreef in bericht
      news:1162724748 .818899.49240@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;
      }

      }

      Comment

      Working...