SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 vb.net connect sql server
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

jagguy
Starting Member

27 Posts

Posted - 08/19/2008 :  08:41:05  Show Profile  Reply with Quote
i get this error and dont know what to do next.

i havent connected to sql server before from vb.net 2008 express


An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)


Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form

Private da As New SqlDataAdapter

Private ds As New DataSet
Private DeptBinder As CurrencyManager
'Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\andrew visual basic\school7\db1.mdb;")
Dim cn As New SqlConnection("server=localhost;uid=jagguy;pwd=mexican;database=test1")



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

LoadDepartments()
BindControls()

End Sub

Private Sub LoadDepartments()


Dim cmd As New SqlCommand
Dim count As Integer

cmd.Connection = cn
cmd.CommandText = "Select * From table2"

da.SelectCommand = cmd
da.Fill(ds, "student")



End Sub

Private Sub BindControls()

DeptBinder = Me.BindingContext(ds, "student")
txtone.DataBindings.Add("Text", ds, "student.one")
txttwo.DataBindings.Add("Text", ds, "student.two")
txtthree.DataBindings.Add("Text", ds, "student.three")

End Sub

rmiao
Flowing Fount of Yak Knowledge

USA
7266 Posts

Posted - 08/20/2008 :  00:05:30  Show Profile  Reply with Quote
>> ("server=localhost;uid=jagguy;pwd=mexican;database=test1")

Replace localhost with real sql instance name.
Go to Top of Page

jagguy
Starting Member

27 Posts

Posted - 08/20/2008 :  02:53:15  Show Profile  Reply with Quote
Dim cn As New SqlConnection("Data Source=JAGGUY2-1PD810A\SQLEXPRESS;Initial Catalog=test1;User Id=jagguy;Password=mexican;")

i get
Login failed for user 'jagguy'. The user is not associated with a trusted SQL Server connection.

1)now i have login jagguy but i cant see where i can check the user? now what?
Go to Top of Page

jagguy
Starting Member

27 Posts

Posted - 08/20/2008 :  18:58:21  Show Profile  Reply with Quote
I can connect and view my database data in vb.net using this

Dim cn As New SqlConnection("Data Source=JAGGUY2-1PD810A\SQLEXPRESS;Initial Catalog=test1;Integrated Security=True;")


However I need to set a password and login on the database.

why did this fail because again with this I get and i want a password and user set as below.

Dim cn As New SqlConnection("Data Source=JAGGUY2-1PD810A;Initial Catalog=test1;User Id=jagguy2;Password=mexican;")

I created a login using SQL Server Authentication (with a username and a login and password as there is no user field).

I Right Click you login 'jagguy2' and click properties. and then set
Server Role as sysadmin,
User Mapping as test1 DB.

It still fails!!!!
Dim cn As New SqlConnection("Data Source=JAGGUY2-1PD810A;Initial Catalog=test1;User Id=jagguy2;Password=mexican;")
Go to Top of Page

rmiao
Flowing Fount of Yak Knowledge

USA
7266 Posts

Posted - 08/20/2008 :  23:54:01  Show Profile  Reply with Quote
You have to create sql login 'jagguy' in sql server first, can do it in ssmse or with sp_addlogin via sqlcmd.
Go to Top of Page

jagguy
Starting Member

27 Posts

Posted - 08/21/2008 :  02:35:59  Show Profile  Reply with Quote
i think this is a given

no i cant connect if i use sql server authentication on mssmse but can on windows authentication

i mean the database has the user and login.
i cant see where i have not done this correctly
Go to Top of Page

jagguy
Starting Member

27 Posts

Posted - 08/21/2008 :  06:51:45  Show Profile  Reply with Quote
tried the below and still didnt work.
is this the most confusing software package i have dealt with?

unless i get help here I cant do this because it just doesnt work for me.

i think this is the 3rd day i have tried to simply connect to sql server.

http://www.datamasker.com/SSE2005_NetworkCfg.htm
Go to Top of Page

afrika
Flowing Fount of Yak Knowledge

Nigeria
2706 Posts

Posted - 08/21/2008 :  08:12:52  Show Profile  Reply with Quote
www.connectionstrings.com
Go to Top of Page

jagguy
Starting Member

27 Posts

Posted - 08/21/2008 :  18:56:58  Show Profile  Reply with Quote
I have already seen the connection strings and I have been using it
Dim cn As New SqlConnection("Data Source=JAGGUY2-1PD810A\SQLEXPRESS;Initial Catalog=test1;Integrated Security=True;")




has anyone been reading my posts as I mentioned what i have done.

This is day 4 on trying to underdstand how to connect to a DB and yes this is annoying!
The DB and sql server are on the same PC

Do I need to reinstall with 2008 express?

It is going to take some effort by someone to find the problem else sql server a just a bad product.

no more posts to links please as sql server 2005 express is complicated
Go to Top of Page

tkizer
Almighty SQL Goddess

USA
37466 Posts

Posted - 08/21/2008 :  19:31:01  Show Profile  Visit tkizer's Homepage  Reply with Quote
Please recap everything as your posts are very confusing.

Show us exactly what accounts you have created and exactly what the error is for each.

And SQL Server is not a bad product. Blaming the tool for your lack of knowledge doesn't get you anywhere.

Tara Kizer
Microsoft MVP for Windows Server System - SQL Server
http://weblogs.sqlteam.com/tarad/

Subscribe to my blog
Go to Top of Page

jagguy
Starting Member

27 Posts

Posted - 08/21/2008 :  23:26:10  Show Profile  Reply with Quote
I create an account login and password and user for DB test1.
I can login into my DB using SQL authentication so it works in SSMSE

1.

In SQL Server Management Studio, open Object Explorer and expand the Databases folder.
2.

Expand the database in which to create the new database user.
3.

Right-click the Security folder, point to New, and then click User.
4.

On the General page, enter a name for the new user in the User name box.
5.

In the Login name box, enter the name of a SQL Server login to map to the database user.
6.

what is my problem?
i have sql server on my local machine as i am only testing.

in vb.net i connect to my database with this connection string

Dim cn As New SqlConnection("Data Source=JAGGUY2-1PD810A;Initial Catalog=test1;User Id=jagguy2;Password=mexican;")
cn.open() 'error
An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)

i also tried below without success but sql server and the vb.net app is on the same machine.
http://www.datamasker.com/SSE2005_NetworkCfg.htm

Go to Top of Page

jagguy
Starting Member

27 Posts

Posted - 08/22/2008 :  02:18:36  Show Profile  Reply with Quote
wait it is working now after i rebooted

Dim cn As New SqlConnection("Data Source=JAGGUY2-1PD810A\SQLEXPRESS;Initial Catalog=test1;User Id=xxxxx;Password=xxxx;")
Go to Top of Page

chan_lemo
Starting Member

1 Posts

Posted - 10/14/2008 :  07:17:02  Show Profile  Reply with Quote
try the follwoing links.

http://vb.net-informations.com/ado.net/vb.net-ado.net-tutorial.htm

http://vb.net-informations.com/ado.net-dataproviders/ado.net-dataproviders-tutorial.htm

quote:
Originally posted by jagguy

i get this error and dont know what to do next.

i havent connected to sql server before from vb.net 2008 express


An error has occurred while establishing a connection to the server. When connecting to SQL Server 2005, this failure may be caused by the fact that under the default settings SQL Server does not allow remote connections. (provider: Named Pipes Provider, error: 40 - Could not open a connection to SQL Server)


Imports System.Data
Imports System.Data.SqlClient

Public Class Form1
Inherits System.Windows.Forms.Form

Private da As New SqlDataAdapter

Private ds As New DataSet
Private DeptBinder As CurrencyManager
'Dim cn As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=F:\andrew visual basic\school7\db1.mdb;")
Dim cn As New SqlConnection("server=localhost;uid=jagguy;pwd=mexican;database=test1")



Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

LoadDepartments()
BindControls()

End Sub

Private Sub LoadDepartments()


Dim cmd As New SqlCommand
Dim count As Integer

cmd.Connection = cn
cmd.CommandText = "Select * From table2"

da.SelectCommand = cmd
da.Fill(ds, "student")



End Sub

Private Sub BindControls()

DeptBinder = Me.BindingContext(ds, "student")
txtone.DataBindings.Add("Text", ds, "student.one")
txttwo.DataBindings.Add("Text", ds, "student.two")
txtthree.DataBindings.Add("Text", ds, "student.three")

End Sub

Go to Top of Page

afrika
Flowing Fount of Yak Knowledge

Nigeria
2706 Posts

Posted - 10/14/2008 :  09:00:03  Show Profile  Reply with Quote
quote:
Originally posted by jagguy

wait it is working now after i rebooted

Dim cn As New SqlConnection("Data Source=JAGGUY2-1PD810A\SQLEXPRESS;Initial Catalog=test1;User Id=xxxxx;Password=xxxx;")




Would advice you to keep your connection string in your web.config file. VStudio does this automatically for you, so you dont have to bother yourself with all the codes.

then all you do is declare a variable to hold the value



Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.12 seconds. Powered By: Snitz Forums 2000