-
Apr 11th, 2006, 12:33 AM
#1
Thread Starter
Member
[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:
Private Sub btnCreate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCreate.Click
Dim myConn As SqlConnection = New SqlConnection("Server=(local);database=master")
str = "CREATE DATABASE questDatabase ON (NAME=questDatabase, FILENAME='C:\Inetpub\wwwroot\database\questDatabase.mdf') " & _
"LOG ON (NAME=questDatabaseLog, FILENAME='C:\Inetpub\wwwroot\database\questDatabaseLog.ldf')"
Dim myCommand As SqlCommand = New SqlCommand(str, myConn)
Try
myConn.Open()
myCommand.ExecuteNonQuery()
Catch ex As Exception
MsgBox(ex.ToString())
End Try
myConn.Close()
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.
-
Apr 11th, 2006, 03:49 AM
#2
Frenzied Member
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
-
Apr 11th, 2006, 10:41 AM
#3
Thread Starter
Member
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
-
Apr 11th, 2006, 01:07 PM
#4
Frenzied Member
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
-
Apr 11th, 2006, 01:10 PM
#5
Junior Member
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
-
Apr 11th, 2006, 01:48 PM
#6
Frenzied Member
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 ?
-
Apr 11th, 2006, 03:20 PM
#7
Thread Starter
Member
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 . . .
-
Apr 11th, 2006, 03:35 PM
#8
Thread Starter
Member
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|