Results 1 to 7 of 7

Thread: Connecting to an SQL Server

  1. #1

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Connecting to an SQL Server

    My attempt to conenct to an SQL database when I click on a 'submit' button on my ASPX page fails with the following error: "[DBNETLIB][ConnectionOpen (Connect()).]SQL Server does not exist or access denied."

    Here is my ASP code:
    Code:
    <script runat="server">
    	Sub submit(sender As Object, e As EventArgs)
    		dim dbconn
    		dbconn=New OleDbConnection("Provider=SQLOLEDB.1;Data Source=ex1;Initial Catalog=TOPS;User ID=sa;Password=XXXX")
    		dbconn.Open()
    	End Sub
    </script>
    The SQL server is on another machine in the network (not the machine running IIS) and I know for a fact that the connection string and login details are correct because they work fine if I open a connection from anywhere else. It is only from within my ASPX page that it fails...

    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  2. #2
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Connecting to an SQL Server

    You should be using SqlConnection, SqlCommand etc. (all part of System.Data.SqlClient) namespace rather than OleDb.

    Your connection string can be something like:
    "server=ServerName;uid=sa;pwd=XXXXX;database=DatabaseName"

    Where ServerName is the host name or IP address of the server the SQL Server is hosted on.

    HTH

    DJ

  3. #3

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Connecting to an SQL Server

    Thanks, but I get the same error...
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  4. #4
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Connecting to an SQL Server

    Have you tried pinging the SQL Server machine from the machine with IIS to ensure they can connect to each other?

    DJ

  5. #5

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Connecting to an SQL Server

    Yes, the machine can connect to the SQL server database with the above connection string in any other place other than within IIS.

    Incidentally, is there any real reason why I should use SqlClient rather OleDb? Is it more efficient for SQL Server databases or something?
    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

  6. #6
    Frenzied Member dj4uk's Avatar
    Join Date
    Aug 2002
    Location
    Birmingham, UK Lobotomies: 3
    Posts
    1,131

    Re: Connecting to an SQL Server

    OleDb will work but as the SqlClient namespace was specifically written for SQL Server it gives better performance etc. I would definately recommend using it.

    If the machines can physically connect there must be something wrong in the connection string or the uid and password ain't right or the SQL Server is turned off

    DJ

  7. #7

    Thread Starter
    Fanatic Member simonm's Avatar
    Join Date
    Sep 2000
    Location
    Devon, England
    Posts
    796

    Re: Connecting to an SQL Server

    I have a test VB.NET application sitting on the IIS machine that does nothing but open a connection object in an identical way with an identical connection string and it works fine.

    Therefore, it must be something to do with ASP.NET or IIS...

    Everything I say is either loose interpretation of dubious facts or idle speculation rooted in irrational sentiment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width