Author |
Topic |
jagguy
Starting Member
27 Posts |
Posted - 2008-08-19 : 08:41:05
|
i get this error and dont know what to do next.i havent connected to sql server before from vb.net 2008 expressAn 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.DataImports 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
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-08-20 : 00:05:30
|
>> ("server=localhost;uid=jagguy;pwd=mexican;database=test1")Replace localhost with real sql instance name. |
|
|
jagguy
Starting Member
27 Posts |
Posted - 2008-08-20 : 02:53:15
|
Dim cn As New SqlConnection("Data Source=JAGGUY2-1PD810A\SQLEXPRESS;Initial Catalog=test1;User Id=jagguy;Password=mexican;")i getLogin 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? |
|
|
jagguy
Starting Member
27 Posts |
Posted - 2008-08-20 : 18:58:21
|
I can connect and view my database data in vb.net using thisDim 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;") |
|
|
rmiao
Master Smack Fu Yak Hacker
7266 Posts |
Posted - 2008-08-20 : 23:54:01
|
You have to create sql login 'jagguy' in sql server first, can do it in ssmse or with sp_addlogin via sqlcmd. |
|
|
jagguy
Starting Member
27 Posts |
Posted - 2008-08-21 : 02:35:59
|
i think this is a givenno i cant connect if i use sql server authentication on mssmse but can on windows authenticationi mean the database has the user and login.i cant see where i have not done this correctly |
|
|
jagguy
Starting Member
27 Posts |
Posted - 2008-08-21 : 06:51:45
|
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 |
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2008-08-21 : 08:12:52
|
www.connectionstrings.com |
|
|
jagguy
Starting Member
27 Posts |
Posted - 2008-08-21 : 18:56:58
|
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 |
|
|
tkizer
Almighty SQL Goddess
38200 Posts |
Posted - 2008-08-21 : 19:31:01
|
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 KizerMicrosoft MVP for Windows Server System - SQL Serverhttp://weblogs.sqlteam.com/tarad/Subscribe to my blog |
|
|
jagguy
Starting Member
27 Posts |
Posted - 2008-08-21 : 23:26:10
|
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 stringDim cn As New SqlConnection("Data Source=JAGGUY2-1PD810A;Initial Catalog=test1;User Id=jagguy2;Password=mexican;")cn.open() 'errorAn 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 |
|
|
jagguy
Starting Member
27 Posts |
Posted - 2008-08-22 : 02:18:36
|
wait it is working now after i rebootedDim cn As New SqlConnection("Data Source=JAGGUY2-1PD810A\SQLEXPRESS;Initial Catalog=test1;User Id=xxxxx;Password=xxxx;") |
|
|
chan_lemo
Starting Member
1 Post |
Posted - 2008-10-14 : 07:17:02
|
try the follwoing links.http://vb.net-informations.com/ado.net/vb.net-ado.net-tutorial.htmhttp://vb.net-informations.com/ado.net-dataproviders/ado.net-dataproviders-tutorial.htmquote: 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 expressAn 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.DataImports 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
|
|
|
afrika
Master Smack Fu Yak Hacker
2706 Posts |
Posted - 2008-10-14 : 09:00:03
|
quote: Originally posted by jagguy wait it is working now after i rebootedDim 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 |
|
|
|