473,795 Members | 2,911 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem connecting to SQL Server

bob
Can anyone help me connect to SQL Server???

I am new to all this... it is been a titanic struggle consuming hours &

days & ....

I am trying to create an SQL database programatically . But my code
stalls before it gets started, and can't establish a connection to SQL
Server.
Here is my code:

=============== =============== =============== ===========

Sub MakeDatabase()
Dim cn As New SqlConnection, cmd As New SqlCommand
Dim connect$, sql$

connect$ = "Data Source=(local); Integrated Security=SSPI;
Initial Catalog=;"
cn.ConnectionSt ring = Connect$

Try
cn.Open()
Catch ae As SqlException
MsgBox(ae.Messa ge.ToString, MsgBoxStyle.Cri tical, "SQL
Connection")
Exit Sub
End Try

sql$ = "CREATE DATABASE Cf"

cmd.Connection = cn
cmd.CommandText = sql$
cmd.ExecuteNonQ uery()

cn.Close()
End Sub

This thing stalls and can't connect, giving me an error #5. The error
message suggest that my installed SQL might not allow "remote access".
But I checked and it does. I am using VB 2005 Express and SQL 2005
Express.

Jun 13 '06 #1
14 2253

<bo*@datasync.c om> wrote in message
news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
Can anyone help me connect to SQL Server???

I am new to all this... it is been a titanic struggle consuming hours &

days & ....

I am trying to create an SQL database programatically . But my code
stalls before it gets started, and can't establish a connection to SQL
Server.
Here is my code:

=============== =============== =============== ===========

Sub MakeDatabase()
Dim cn As New SqlConnection, cmd As New SqlCommand
Dim connect$, sql$

connect$ = "Data Source=(local); Integrated Security=SSPI;
Initial Catalog=;"
cn.ConnectionSt ring = Connect$

Try
cn.Open()
Catch ae As SqlException
MsgBox(ae.Messa ge.ToString, MsgBoxStyle.Cri tical, "SQL
Connection")
Exit Sub
End Try

sql$ = "CREATE DATABASE Cf"

cmd.Connection = cn
cmd.CommandText = sql$
cmd.ExecuteNonQ uery()

cn.Close()
End Sub

This thing stalls and can't connect, giving me an error #5. The error
message suggest that my installed SQL might not allow "remote access".
But I checked and it does. I am using VB 2005 Express and SQL 2005
Express.

Try replacing the "(local)" in your connection string with either
"<machinename>\ SqlExpress", or ".\SqlExpre ss".

Here, SQL 2005 Express installs a named instance, using the name SqlExpress.
If your SQL Server instance is anonymous, don't add the \SqlExpress.
Also had issues here with (local). Replacing (local) with either of the
above fixed the connection.

Jun 13 '06 #2
Bob,

When you installed SQL Server 2005 Express did you take the default of
installing a named instance? (The install wants to create a named instance
named SQLExpress).

If so, then try changing the data source in the connect string to:

Data Source=(local)\ SQLExpress;

Kerry Moorman

"bo*@datasync.c om" wrote:
Can anyone help me connect to SQL Server???

I am new to all this... it is been a titanic struggle consuming hours &

days & ....

I am trying to create an SQL database programatically . But my code
stalls before it gets started, and can't establish a connection to SQL
Server.
Here is my code:

=============== =============== =============== ===========

Sub MakeDatabase()
Dim cn As New SqlConnection, cmd As New SqlCommand
Dim connect$, sql$

connect$ = "Data Source=(local); Integrated Security=SSPI;
Initial Catalog=;"
cn.ConnectionSt ring = Connect$

Try
cn.Open()
Catch ae As SqlException
MsgBox(ae.Messa ge.ToString, MsgBoxStyle.Cri tical, "SQL
Connection")
Exit Sub
End Try

sql$ = "CREATE DATABASE Cf"

cmd.Connection = cn
cmd.CommandText = sql$
cmd.ExecuteNonQ uery()

cn.Close()
End Sub

This thing stalls and can't connect, giving me an error #5. The error
message suggest that my installed SQL might not allow "remote access".
But I checked and it does. I am using VB 2005 Express and SQL 2005
Express.

Jun 13 '06 #3
Bob,

Have a look at this sample on our website.

http://www.vb-tips.com/default.aspx?...1-d6dda3c888c8

I think there is more in than you need, but the information you can use.

You are the first one who uses still sql$ by the way in these newsgroups and
I have seen much.

There is nothing wrong with that, however as written tomorrow by GhostAD,
you don't write a program for the computers, write it to let others know
what you are doing.

I hope this helps,

Cor

<bo*@datasync.c om> schreef in bericht
news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
Can anyone help me connect to SQL Server???

I am new to all this... it is been a titanic struggle consuming hours &

days & ....

I am trying to create an SQL database programatically . But my code
stalls before it gets started, and can't establish a connection to SQL
Server.
Here is my code:

=============== =============== =============== ===========

Sub MakeDatabase()
Dim cn As New SqlConnection, cmd As New SqlCommand
Dim connect$, sql$

connect$ = "Data Source=(local); Integrated Security=SSPI;
Initial Catalog=;"
cn.ConnectionSt ring = Connect$

Try
cn.Open()
Catch ae As SqlException
MsgBox(ae.Messa ge.ToString, MsgBoxStyle.Cri tical, "SQL
Connection")
Exit Sub
End Try

sql$ = "CREATE DATABASE Cf"

cmd.Connection = cn
cmd.CommandText = sql$
cmd.ExecuteNonQ uery()

cn.Close()
End Sub

This thing stalls and can't connect, giving me an error #5. The error
message suggest that my installed SQL might not allow "remote access".
But I checked and it does. I am using VB 2005 Express and SQL 2005
Express.

Jun 13 '06 #4
Doh,

How I did think it was access is almost unbelievable reading the text again.

http://www.vb-tips.com/default.aspx?...a-6680e677e994

Sorry

Cor

<bo*@datasync.c om> schreef in bericht
news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
Can anyone help me connect to SQL Server???

I am new to all this... it is been a titanic struggle consuming hours &

days & ....

I am trying to create an SQL database programatically . But my code
stalls before it gets started, and can't establish a connection to SQL
Server.
Here is my code:

=============== =============== =============== ===========

Sub MakeDatabase()
Dim cn As New SqlConnection, cmd As New SqlCommand
Dim connect$, sql$

connect$ = "Data Source=(local); Integrated Security=SSPI;
Initial Catalog=;"
cn.ConnectionSt ring = Connect$

Try
cn.Open()
Catch ae As SqlException
MsgBox(ae.Messa ge.ToString, MsgBoxStyle.Cri tical, "SQL
Connection")
Exit Sub
End Try

sql$ = "CREATE DATABASE Cf"

cmd.Connection = cn
cmd.CommandText = sql$
cmd.ExecuteNonQ uery()

cn.Close()
End Sub

This thing stalls and can't connect, giving me an error #5. The error
message suggest that my installed SQL might not allow "remote access".
But I checked and it does. I am using VB 2005 Express and SQL 2005
Express.

Jun 13 '06 #5
bob
Thanks! That was the problem all along.
pvdg42 wrote:
<bo*@datasync.c om> wrote in message
news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
Can anyone help me connect to SQL Server???

I am new to all this... it is been a titanic struggle consuming hours &

days & ....

I am trying to create an SQL database programatically . But my code
stalls before it gets started, and can't establish a connection to SQL
Server.
Here is my code:

=============== =============== =============== ===========

Sub MakeDatabase()
Dim cn As New SqlConnection, cmd As New SqlCommand
Dim connect$, sql$

connect$ = "Data Source=(local); Integrated Security=SSPI;
Initial Catalog=;"
cn.ConnectionSt ring = Connect$

Try
cn.Open()
Catch ae As SqlException
MsgBox(ae.Messa ge.ToString, MsgBoxStyle.Cri tical, "SQL
Connection")
Exit Sub
End Try

sql$ = "CREATE DATABASE Cf"

cmd.Connection = cn
cmd.CommandText = sql$
cmd.ExecuteNonQ uery()

cn.Close()
End Sub

This thing stalls and can't connect, giving me an error #5. The error
message suggest that my installed SQL might not allow "remote access".
But I checked and it does. I am using VB 2005 Express and SQL 2005
Express.

Try replacing the "(local)" in your connection string with either
"<machinename>\ SqlExpress", or ".\SqlExpre ss".

Here, SQL 2005 Express installs a named instance, using the name SqlExpress.
If your SQL Server instance is anonymous, don't add the \SqlExpress.
Also had issues here with (local). Replacing (local) with either of the
above fixed the connection.


Jun 13 '06 #6
bob
That must have been it -- using the default during the SQL Server
Express install. Frankly, when I installed it I didn't really know
exactly what was going on... This is my first engagement/battle with
Sql Server.

Thanks so much.
Bob
Kerry Moorman wrote:
Bob,

When you installed SQL Server 2005 Express did you take the default of
installing a named instance? (The install wants to create a named instance
named SQLExpress).

If so, then try changing the data source in the connect string to:

Data Source=(local)\ SQLExpress;

Kerry Moorman

"bo*@datasync.c om" wrote:
Can anyone help me connect to SQL Server???

I am new to all this... it is been a titanic struggle consuming hours &

days & ....

I am trying to create an SQL database programatically . But my code
stalls before it gets started, and can't establish a connection to SQL
Server.
Here is my code:

=============== =============== =============== ===========

Sub MakeDatabase()
Dim cn As New SqlConnection, cmd As New SqlCommand
Dim connect$, sql$

connect$ = "Data Source=(local); Integrated Security=SSPI;
Initial Catalog=;"
cn.ConnectionSt ring = Connect$

Try
cn.Open()
Catch ae As SqlException
MsgBox(ae.Messa ge.ToString, MsgBoxStyle.Cri tical, "SQL
Connection")
Exit Sub
End Try

sql$ = "CREATE DATABASE Cf"

cmd.Connection = cn
cmd.CommandText = sql$
cmd.ExecuteNonQ uery()

cn.Close()
End Sub

This thing stalls and can't connect, giving me an error #5. The error
message suggest that my installed SQL might not allow "remote access".
But I checked and it does. I am using VB 2005 Express and SQL 2005
Express.


Jun 13 '06 #7
bob
Cor, I'm not sure I understand you about still using "sql$". Anyway, I
got the problem fixed, and thanks for the help.

Bob
Cor Ligthert [MVP] wrote:
Bob,

Have a look at this sample on our website.

http://www.vb-tips.com/default.aspx?...1-d6dda3c888c8

I think there is more in than you need, but the information you can use.

You are the first one who uses still sql$ by the way in these newsgroups and
I have seen much.

There is nothing wrong with that, however as written tomorrow by GhostAD,
you don't write a program for the computers, write it to let others know
what you are doing.

I hope this helps,

Cor

<bo*@datasync.c om> schreef in bericht
news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
Can anyone help me connect to SQL Server???

I am new to all this... it is been a titanic struggle consuming hours &

days & ....

I am trying to create an SQL database programatically . But my code
stalls before it gets started, and can't establish a connection to SQL
Server.
Here is my code:

=============== =============== =============== ===========

Sub MakeDatabase()
Dim cn As New SqlConnection, cmd As New SqlCommand
Dim connect$, sql$

connect$ = "Data Source=(local); Integrated Security=SSPI;
Initial Catalog=;"
cn.ConnectionSt ring = Connect$

Try
cn.Open()
Catch ae As SqlException
MsgBox(ae.Messa ge.ToString, MsgBoxStyle.Cri tical, "SQL
Connection")
Exit Sub
End Try

sql$ = "CREATE DATABASE Cf"

cmd.Connection = cn
cmd.CommandText = sql$
cmd.ExecuteNonQ uery()

cn.Close()
End Sub

This thing stalls and can't connect, giving me an error #5. The error
message suggest that my installed SQL might not allow "remote access".
But I checked and it does. I am using VB 2005 Express and SQL 2005
Express.


Jun 13 '06 #8
Bob,

When I had sent my both messages and had read the answers from Peter and
Kerry I saw as well the answer to your problem.

For that there was no need for me to sent another message. Your code is
however in a very personal style: good readable probably by VB diehards, but
not as we see code today. That was what I did mean with my text about the
mystring$. To say it in other words the old literals are not so common
anymore.

In my opinion( but not mine alone) is one of the first commands to create a
program using a program language as VBNet, is to make it maintainable by
others.

Cor

<bo*@datasync.c om> schreef in bericht
news:11******** *************@y 43g2000cwc.goog legroups.com...
Cor, I'm not sure I understand you about still using "sql$". Anyway, I
got the problem fixed, and thanks for the help.

Bob
Cor Ligthert [MVP] wrote:
Bob,

Have a look at this sample on our website.

http://www.vb-tips.com/default.aspx?...1-d6dda3c888c8

I think there is more in than you need, but the information you can use.

You are the first one who uses still sql$ by the way in these newsgroups
and
I have seen much.

There is nothing wrong with that, however as written tomorrow by GhostAD,
you don't write a program for the computers, write it to let others know
what you are doing.

I hope this helps,

Cor

<bo*@datasync.c om> schreef in bericht
news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
> Can anyone help me connect to SQL Server???
>
> I am new to all this... it is been a titanic struggle consuming hours &
>
> days & ....
>
> I am trying to create an SQL database programatically . But my code
> stalls before it gets started, and can't establish a connection to SQL
> Server.
> Here is my code:
>
> =============== =============== =============== ===========
>
> Sub MakeDatabase()
> Dim cn As New SqlConnection, cmd As New SqlCommand
> Dim connect$, sql$
>
> connect$ = "Data Source=(local); Integrated Security=SSPI;
> Initial Catalog=;"
> cn.ConnectionSt ring = Connect$
>
> Try
> cn.Open()
> Catch ae As SqlException
> MsgBox(ae.Messa ge.ToString, MsgBoxStyle.Cri tical, "SQL
> Connection")
> Exit Sub
> End Try
>
> sql$ = "CREATE DATABASE Cf"
>
> cmd.Connection = cn
> cmd.CommandText = sql$
> cmd.ExecuteNonQ uery()
>
> cn.Close()
> End Sub
>
> This thing stalls and can't connect, giving me an error #5. The error
> message suggest that my installed SQL might not allow "remote access".
> But I checked and it does. I am using VB 2005 Express and SQL 2005
> Express.
>

Jun 14 '06 #9
bob
Cor,

I'm glad you brought that up -- I am just in love with those "old
literals". I guess you mean by that that

Dim sql as String

is preferred to

Dim sql$

I think the last form is so much better. Especially when you see people
doing this:

Dim strSql

See what I mean?

(A lot of people must like the "sql$" approach, because I notice that
MS (after threatening to drop this capability) kept it in VB.NET all
the way through VB.NET 2005.
Cor Ligthert [MVP] wrote:
Bob,

When I had sent my both messages and had read the answers from Peter and
Kerry I saw as well the answer to your problem.

For that there was no need for me to sent another message. Your code is
however in a very personal style: good readable probably by VB diehards, but
not as we see code today. That was what I did mean with my text about the
mystring$. To say it in other words the old literals are not so common
anymore.

In my opinion( but not mine alone) is one of the first commands to create a
program using a program language as VBNet, is to make it maintainable by
others.

Cor

<bo*@datasync.c om> schreef in bericht
news:11******** *************@y 43g2000cwc.goog legroups.com...
Cor, I'm not sure I understand you about still using "sql$". Anyway, I
got the problem fixed, and thanks for the help.

Bob
Cor Ligthert [MVP] wrote:
Bob,

Have a look at this sample on our website.

http://www.vb-tips.com/default.aspx?...1-d6dda3c888c8

I think there is more in than you need, but the information you can use.

You are the first one who uses still sql$ by the way in these newsgroups
and
I have seen much.

There is nothing wrong with that, however as written tomorrow by GhostAD,
you don't write a program for the computers, write it to let others know
what you are doing.

I hope this helps,

Cor

<bo*@datasync.c om> schreef in bericht
news:11******** **************@ g10g2000cwb.goo glegroups.com.. .
> Can anyone help me connect to SQL Server???
>
> I am new to all this... it is been a titanic struggle consuming hours &
>
> days & ....
>
> I am trying to create an SQL database programatically . But my code
> stalls before it gets started, and can't establish a connection to SQL
> Server.
> Here is my code:
>
> =============== =============== =============== ===========
>
> Sub MakeDatabase()
> Dim cn As New SqlConnection, cmd As New SqlCommand
> Dim connect$, sql$
>
> connect$ = "Data Source=(local); Integrated Security=SSPI;
> Initial Catalog=;"
> cn.ConnectionSt ring = Connect$
>
> Try
> cn.Open()
> Catch ae As SqlException
> MsgBox(ae.Messa ge.ToString, MsgBoxStyle.Cri tical, "SQL
> Connection")
> Exit Sub
> End Try
>
> sql$ = "CREATE DATABASE Cf"
>
> cmd.Connection = cn
> cmd.CommandText = sql$
> cmd.ExecuteNonQ uery()
>
> cn.Close()
> End Sub
>
> This thing stalls and can't connect, giving me an error #5. The error
> message suggest that my installed SQL might not allow "remote access".
> But I checked and it does. I am using VB 2005 Express and SQL 2005
> Express.
>


Jun 14 '06 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2548
by: Ali | last post by:
I'm trying to write a really basic chat program that allows 2 client programs to send messages to each other via a server. I've managed to write the code so that both clients can connect to the server and send and recieve messages to/from the server but when I send a message from one client I can't get the message to appear in the second client. I think it's something to do with threads but I don't know what! I've been looking at the...
1
3798
by: Dmitry Akselrod | last post by:
Hello everyone, I have a vb.net application that wraps the TCPListener object in a class. The server connects to the local interface and establishes itself on port 9900. It then polls for pending connections every 500ms. I also have a vb6 application that uses the WinSock control at the other end of the communication tunel. I have to work with vb6 here because it uses less memory than .NET.
12
2795
by: Ann Marinas | last post by:
Hi all, I would like to ask for some help regarding separating the asp.net webserver and the sql server. I have created an asp.net application for a certain company. Initially, we installed both the iis and sql server in a single machine. Not too long ago, the machine had some hardware problems, and management has decided to purchase new servers, for both asp.net and sql server.
0
1922
by: richard | last post by:
OS: Winxp and Win2003 Visual Basic.NET 2003 MS-SQL Server 2000 hey all I am a newbie in vb.net but i have managed to build a simple chat server in vb.net using socket and a client connecting to it made in vb6. Some of the code in the server are based on the basic samples that i get from other authors. To give you an idea, the server uses sockets,
2
3561
by: John | last post by:
Hi I was working fine with create user wizard and the default membership provider. I have now customised the membership provider as per attached web.config. The create user wizard picks up the custom membership provider fine and removes the security question/answer fields as designated in the custom provider. The problem is that when I try to create a new user in the create user wizard by entering the info and pressing the 'create...
9
2704
by: RvGrah | last post by:
After much hair-pulling, I've finally found the answer to a problem that many are fighting with, difficulty connecting from Sql 2005 Server Management or VS2005 to a remote Sql Server running Sql 2000. In my case the server I couldn't reach was across a vpn connection, behind ISA server 2000, (which had port 1433 open). The answer was in this post:...
0
3925
by: Suresh | last post by:
Hi Guys I have Db2 server installed on remote server. i am connecting to that remote server by using VPN. I want to connect that remote DB2 server instance using my local machine DB2 development client. Bur Its gives me following error message. I searched lots of things on net and tried on remote server but i didnt got suceess. Can any one tell me how to set TCP\IP connection protocol on server for particular instance. Becuase I think
0
2869
by: NoaGross | last post by:
Hi, I'm relly new in java and I have a problem. I'm using java applet. When using http all ok, but when trying to use https i get: Java Plug-in 1.5.0_10 Using JRE version 1.5.0_10 Java HotSpot(TM) Client VM User home directory = C:\Documents and Settings\noa ---------------------------------------------------- c: clear console window
9
4304
by: darthghandi | last post by:
I am trying to create a server application using asynchronous sockets. I run into a problem when I try to connect to my server using a non-.net program. I can establish the connection, and send some packets in response to the programs first message, but when I receive a response back, it's the last packet I sent. After that packet, I receive the packet I really wanted. This only happens when I connect with local host. I tried...
2
3046
by: orandov | last post by:
Hi, I am having a problem connecting my .net applications from the application server to the database server. When I run the application from my windows xp (sp2) box it works fine. When I try to connect via SQL Management Studio to the database server from the application server I get the same error. Here is the error:
0
9672
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9519
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10215
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10165
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9043
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7541
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5563
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4113
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3727
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.