Results 1 to 8 of 8

Thread: [RESOLVED] SqlConnection.Open() issues

  1. #1

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    37

    Resolved [RESOLVED] SqlConnection.Open() issues

    I am writing a simple program with Visual Studio 2003(VB.NET) which, of many things, creates a database. I have downloaded and installed Micrososft SQL Server 2005 Express and the "SQL Server (SQLEXPRESS)" service is running. However, when I try to open the connection to the server I get an error saying the server either does not exist or cannot be accessed. I've tried going to the properties of the SQL service and changing the "Log On As" property to Local System, Local Service, and Network Service, none of which work. Here's my code if anyone can help I'd greatly appreciate it

    edit: Also I have imported System.Data.SqlClient
    One more thing, I'm using VS 2003, but I've installed the .Net 2.0 library

    VB Code:
    1. Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
    2.  
    3.         Dim myConn As SqlConnection = New SqlConnection("Server=(local);database=master")
    4.  
    5.         str = "CREATE DATABASE questDatabase ON (NAME=questDatabase, FILENAME='C:\Inetpub\wwwroot\database\questDatabase.mdf') " & _
    6.                     "LOG ON (NAME=questDatabaseLog, FILENAME='C:\Inetpub\wwwroot\database\questDatabaseLog.ldf')"
    7.  
    8.         Dim myCommand As SqlCommand = New SqlCommand(str, myConn)
    9.  
    10.         Try
    11.             myConn.Open()
    12.             myCommand.ExecuteNonQuery()
    13.         Catch ex As Exception
    14.             MsgBox(ex.ToString())
    15.         End Try
    16.  
    17.         myConn.Close()
    18.  
    19.     End Sub

    btw sorry if SQL questions do not belong here, I did not see anything specifically stating they do, but at the same time I saw nothing saying they do not and this is related to VB. NET . . .
    Last edited by JSand4325; Apr 11th, 2006 at 03:36 PM.

  2. #2
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: [02/03] SqlConnection.Open() issues

    One more thing, I'm using VS 2003, but I've installed the .Net 2.0 library
    this should never be a problem, but you must keep .net framework 1.1 on the machine.

    .net framework 2 has several issues and doesn't support 1.x in a safe manner

    that is what i read up to now

  3. #3

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    37

    Re: [02/03] SqlConnection.Open() issues

    .net 1.1 is still on my computer and when I look in the help -> about menu it shows that it is using .NET 1.1

  4. #4
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: [02/03] SqlConnection.Open() issues

    i had the same problem once when trying to access sql server 2000 on windows 2003 server. itried to connect to sql server using server fixed ip but i failed. the solution was just to install sql server service pack 4 (but this happened for sqlserver 2000) still i didn't try sql server 2005 yet.

    good luck

  5. #5
    Junior Member babe21's Avatar
    Join Date
    Apr 2006
    Location
    Canada
    Posts
    23

    Re: [02/03] SqlConnection.Open() issues

    make sure you check your names, i got that problem becuase the company changed the name of the sever on me, also make sure that the server is on and is availible
    ~*Babe*~*~21*~

  6. #6
    Frenzied Member maged's Avatar
    Join Date
    Nov 2002
    Location
    Egypt
    Posts
    1,040

    Re: [02/03] SqlConnection.Open() issues

    i got that problem becuase the company changed the name of the sever on me, also make sure that the server is on and is availible
    i think he is testing on local machine !


    am i right ?

  7. #7

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    37

    Re: [02/03] SqlConnection.Open() issues

    Yes as of now this is all local. According to Microsoft I just put "server=(Local); database=master" for the connection string. Here's a link to the article I read to help me do this. I realize my connection string is very simple after I get this going I'll probably add more to it.

    http://support.microsoft.com/kb/305079

    they also have \netsdk after (Local) in the server definition, I've tried with and without and it does not work. I don't know what the purpose of \netsdk is . . .

  8. #8

    Thread Starter
    Member
    Join Date
    Nov 2005
    Posts
    37

    Re: [02/03] SqlConnection.Open() issues

    I got it! It had to do with that \netsdk. I looked up SQL 2005 connection strings and found that for SQL Express I would make it \SQLExpress.

    Hurray www.connectionstrings.com !

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