Showing posts with label databse. Show all posts
Showing posts with label databse. Show all posts

Thursday, March 22, 2012

Error in the login process when establishing connection

Hello,

I am trying to connect to a database through a web service. I am being able to connect to the databse through the server explorer in Visual Studio 2005, but when I try to do it with code in my application this is the message I get:

A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)

My code looks like this:

SqlConnection thisConnection = new SqlConnection(@."Data Source=vse1092;Initial Catalog=CurrituckDB;Integrated Security=True;"); //User id=;Password=;");

thisConnection.Open();

I also tried putting my user id and password... but same message appears.

Any help will be greatly appreciated.

Thanks,
David

Do you have the upto date SQL server express, the one that corresponds with the version of Visual Studio
|||Try with VS.NET 2003|||Also, you can try looking in the server error log (by default at "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG") for an error message that might be more informative. Look for messages that correspond in time to the failed login attempts when you run the client application.

Hope this helps,
Vaughn|||Hi,
I faced a similar issue few days back. The issue was solved when I removed the Windows 2003 Service pack1 from my system. Try removing the service pack. If U have it installed or try removing security updates that U've recently installed.

By the way, are U able to connect to the database using the management studio ot enterprise manageer?|||In addition, please check out the SQL Protocols Blog (http://blogs.msdn.com/sql_protocols/) which contains a troubleshooting connectivity series.|||Hmmm... The best way to figure this out is by looking through the error log (as Vaughn suggested). If we had a bit more information about your configuration we could probably conjecture a bit more here.
One place we've seen this happen before is when the client stacks (in your case SQLClient) and the server are mismatched intermediate versions - for example, .Net Framework 2.0 beta 2 running against SQL Server 2005 beta 2. If you have mismatched intermediate releases, you'd see something like this.

There are other reasons you might see this. There's a swath of blogs up on http://blogs.msdn.com/sql_protocols that might have the answer your looking for.

Thanks.sql

Error in the login process when establishing connection

Hello,

I am trying to connect to a database through a web service. I am being able to connect to the databse through the server explorer in Visual Studio 2005, but when I try to do it with code in my application this is the message I get:

A connection was successfully established with the server, but then an error occurred during the login process. (provider: TCP Provider, error: 0 - An existing connection was forcibly closed by the remote host.)

My code looks like this:

SqlConnection thisConnection = new SqlConnection(@."Data Source=vse1092;Initial Catalog=CurrituckDB;Integrated Security=True;"); //User id=;Password=;");

thisConnection.Open();

I also tried putting my user id and password... but same message appears.

Any help will be greatly appreciated.

Thanks,
David

Do you have the upto date SQL server express, the one that corresponds with the version of Visual Studio|||Try with VS.NET 2003|||Also, you can try looking in the server error log (by default at "C:\Program Files\Microsoft SQL Server\MSSQL.1\MSSQL\LOG\ERRORLOG") for an error message that might be more informative. Look for messages that correspond in time to the failed login attempts when you run the client application.

Hope this helps,
Vaughn|||Hi,
I faced a similar issue few days back. The issue was solved when I removed the Windows 2003 Service pack1 from my system. Try removing the service pack. If U have it installed or try removing security updates that U've recently installed.

By the way, are U able to connect to the database using the management studio ot enterprise manageer?|||In addition, please check out the SQL Protocols Blog (http://blogs.msdn.com/sql_protocols/) which contains a troubleshooting connectivity series.|||Hmmm... The best way to figure this out is by looking through the error log (as Vaughn suggested). If we had a bit more information about your configuration we could probably conjecture a bit more here.
One place we've seen this happen before is when the client stacks (in your case SQLClient) and the server are mismatched intermediate versions - for example, .Net Framework 2.0 beta 2 running against SQL Server 2005 beta 2. If you have mismatched intermediate releases, you'd see something like this.

There are other reasons you might see this. There's a swath of blogs up on http://blogs.msdn.com/sql_protocols that might have the answer your looking for.

Thanks.

Wednesday, March 7, 2012

error in fetching data

hello i'm using visual studio 2005 and asp.net 2 i have an error in the code that fetching data from databse in grid here is the code :

Dim con As SqlConnection
con = New SqlConnection("Data Source=local;AttachDbFilename='D:\New Folder\horus\horus.mdf';Integrated Security=True")
Dim cmd As New String("SELECT TOP (10) serial, name, gender, dateofbirth FROM(dbo.students)ORDER BY RAND(CONVERT(varbinary(4), NEWID()))")
Dim cd As SqlDataAdapter
cd = New SqlDataAdapter(cmd, con)
Dim ds As New DataSet()
cd.Fill(ds, "students")
grid.DataSource = ds.Tables("students").DefaultView
grid.DataBind()

that code is selecting random records from the database and showing it in grid the error is in the cd.fill(ds,"students") line so can any one help me in that problem.thanksAre you sure your query (SQL) statement is valid? I've never seen RAND() specified in ORDER BY clause before. ORDER BY clause usually requires a list of column names. Did you try running the query in MS-SQL directly to see if it works?|||

No, the SQL statement isn't valid, there must be some kind of language barrier here because I've pointed that out twice before, but not because of the RAND(). You can't put your table names in parenthesis like that.

Wrong:

Dim cmd As New String("SELECT TOP (10) serial, name, gender, dateofbirth FROM(dbo.students)ORDER BY RAND(CONVERT(varbinary(4), NEWID()))")

Right:

Dim cmd As New String("SELECT TOP (10) serial, name, gender, dateofbirth FROM dbo.students ORDER BY RAND(CONVERT(varbinary(4), NEWID()))")

|||hello Motley that code is not showing anything as i said in the other topic, anyway i have another code that serch for name and also not working hope u tell me what is the error in that line :
("SELECT tserial,name,subjectname,stage,class FROM teachers WHERE name =' &TextBox1.Text'&", con)

thanks|||

You should change to use parameterized queries in order to avoid SQL Injection attacks.

This will "fix" your problem, but leave a huge security hole in your application:

("SELECT tserial,name,subjectname,stage,class FROM teachers WHERE name='" &TextBox1.Text&"'", con)

Note that that is name, equals, single quote, double quote, ampersand, Textbox1.text, ampersand, double quote, single quote, double quote.

|||hello, ok that code is ok i have another code problem i have two dropdownlist the first one has the name of the tables in my database the second one has a value in column in all these tables the problem is the server cant get the table name from the dropdownlist here is the code :
Dim con As New SqlConnection("Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\mydb.mdf;Integrated Security=True;User Instance=True")
Dim com As New SqlDataAdapter("SELECT * FROM " & ddl1.SelectedValue & "WHERE class = " & ddl2.SelectedValue, con)
Dim ds As New DataSet()
com.Fill(ds, ddl1.SelectedValue)
grid.DataSource = ds.Tables(ddl1.SelectedValue).DefaultView
grid.DataBind()

the table name is in the value of the dropdownlist by the way this a periods tables for a school and every stage has three classes so the column class is in all the tables, hope u can help thanks.|||no one can help?!!! i'm close to finish the site hope u can help.|||Try assigning the SELECT statement into a string variable to verify whether or not there is any syntax error. Also, try out the hard-coded string to make sure the SQL works in the first place. Finally, unless your "class" column is an integer type, you should quote the value using single quotes.|||hello jcasp i tried what u told me the sql statement is alright but the problem is in that dropdown list i typed its value as the name of the table but it doesnt work i tried to put single quotes in that line "WHERE class = " & 'ddl2.SelectedValue', con) i put ddl2.selectedvalue between the single quotes but it put a blue line under the & so hope u can help and by the way the class is not integer it's varchar, hope u can help me soon i'm really close to do it.|||hey guys i just need a little help to make it, i'm waiting ur replies.|||To enclose the value in single quotes, the syntax should be:

"WHERE class ='" & ddl2.SelectedValue & "'", con)
|||

Bad design. Move all the class tables into a single table with a column that has a class name column. Then do this:

Dim conn as new SqlCommand("{Connecting String here}")
conn.open
Dim cmd as new SqlCommand("SELECT * FROM MyClassTable WHEREClassName=@.ClassName AND Class=@.Class",conn)
cmd.parameters.add("@.ClassName",sqldbtype.varchar).Value=ddl1.Selectedvalue
cmd.parameters.add("@.Class",sqldbtype.varchar).Value=ddl2.SelectedValue
dim ds as new DataSet()
dim com as new sqldataadapter(cmd)
com.fill(ds,"MyClassTable")
grid.Datasource=ds.Tables(0).DefaultView
grid.Databind

|||hello Motley i guess i will do as u said and make them all in one table but i will do it with the datasourceWink [;)] i just have a last question i want to add my tables to the aspnetdb the default database in visual studio so can u tell me how to do that thanks for ur endless helpSmile [:)]|||up!!!|||I have no magic way of making it easy. I use Management Studio, and it's not easy -- I run the export/import wizard to move as much as it will, then go back and apply my indexes, trigger, primary keys, etc.