Showing posts with label visual. Show all posts
Showing posts with label visual. Show all posts

Thursday, March 29, 2012

Error locating server/instance specified

I am trying to connect to the AdventureWorks database while using Visual Basic 2005 Express. I am currently using the SQL Server 2005 trial version. Here is the error message:

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: SQL Network Interfaces, Error: 26 - Error locating server/instance specified)

I found some threads in the archives when I researched this problem but couldn't relate the answers directly to my situation. Prior to installing SQL Server 2005 Trial version, I used the SQL Server 2005 Express edition on this machine and did not have any problems connecting to databases. I removed the express edition prior to installing the trial version.

In the Visual Basic "Add Connection" dialog box, I leave the default radio button checked ("Use Windows Authentication") as I have always done.

Any help in getting this resolved will be appreciated.

Use the Surface Area Configuration Tool to see if the server is able to accept connections.

In addition when you installed did you give the instance a name or did you leave it as the default?

|||

Hi Euan:

I installed the program using the default settings (which seemed to work fine for the Express version that I had used previously).

Following your suggestion, I opened up the Surface Area Configuration Tool and set all the items to "automatic" thinking that would allow the maximum access to the databases. Since I am only using it on one machine for evaluation, I am not worried about security at this point. I just want to get it to work with Visual Basic.

When I tried to connect to AdventureWorks in Visual Basic 2005 Express, I got the same error message as before.

Any thoughts on how to proceed?

|||

Is the SQL Server on the same machine as the VB code or on a different machine?

Can you please go into the Windows Services Control GUI from Control Panel and check the list of installed services, please list all the ones that start with mssql and say what their service status is.

What are you using as a connection string to the database(this might be in the property of a control so search the project for server=)

|||

VB and SQL Server are on the same machine.

I am using XP Home Edition. Here is what I found under Administrative Tools\Services:

SQL Server (MSSQLSERVER)Started

SQL Server AgentStarted

SQL Server Analysis Services (MSSQLSERVER)Started

SQL Server FullText Search (MSSQLSERVER)Started

I am attempting to connect via the menu - "Tools\Connect to Database" which brings up the "Add Connection" Wizard. There is to place to enter a connection string.

If I add a control such as the DataGridView and try to link it to a data source, I end up back at the "Add Connection" Wizard without being able to enter a connection string.

|||Can you please try conecting via sqlcmd and the command line please?|||

Thanks for your help Euan:

As a total Newbie, I am not familiar with using sqlcmd or the command prompt.After some reading in the MSDN books online I did the following:

I clicked “Start”

I clicked “Run”

I typed in “sqlcmd” and clicked “OK”

I typed in “select @.@.servername go” and clicked “Enter”

The program returned “Office” (1 row affected)

I assume that I connected to SQL Server 2005 using sqlcmd since “Office” is the server name I connect to with SQL Server Management Studio.

|||So when you try and connect from VS what connection string are you using?|||

As stated previously, I have been attempting to connect via the menu - "Tools\Connect to Database" which brings up the "Add Connection" Wizard. There is to place to enter a connection string. I have used the "Add Connection" Wizard previously with SQL 2005 Express to connect to several databases without any problems.

I have also tried via Database Explorer and Data Sources which have both eventually taken me to the same "Add Connection" Wizard resulting in the same error message.

I just tried something different that may help resolve this issue.

I tried adding the AdventureWorks database via Solution Explorer, right clicking the project and then add existing resource. I browsed to and clicked the AdventureWorks db and got the following error message:

Connections to SQL Server files (*.mdf) require SQL Server Express 2005 to function properly. Please verify the installation of the component or download from the URL: http://go.microsoft.com/fwlink/?LinkID=49251

I clicked OK to exit the message box and Solution Explorer then added AdventureWorks database to the project. But when I tried to connect as described above, I got the orignal error message about not locating the server.

Questions:

1. If I am using Visual Basic 2005 Express, do I have to have SQL Server Express 2005 installed to connect to an .mdf database?

2. If so, can SQL Server trial version and SQl Server Express 2005 be installed and run properly on the same machine?

3. Or is VB 2005E simply remembering that it had used SQL Server Express 2005 previously to connect to databases and is insisting on using it again instead of the SQL Server trial version?

|||The same exact thing happened with me. I am currently using visual basic 2005 express edition and SQL 2000. Everything seems to be working fine, but everytime i try to open a database using vb, it takes me to the exact same screen (where it asks me for the file path) and whether i want it to be a windows authentication or sql server. I tried both, and they give me the same error as well. Please let me know if someone knows how to solve this, my email address is shahkevat@.hotmail.com.|||Kevat, you are using a feature called user instances that is only available in SQL Server Express 2005, not SQL 2000. either connect to the database as a service (ie not a file) or install SQL Express|||

Moonshadow,

There are 2 ways of conencting to SQL Server I seem to remember one is file and one is database, I am guessing you are choosing file? Can you try using database please?

|||I had a problem with not being able to view my local server thru' Visual Studio 2005. Per the information on this thread, i saw the windows services under control panel -> Administrative tools on my windows XP professional box and turned on the service called "SQL Server Browser" which broadcasts the service from ur machine. (If i understand it correctly). After, that it was smooth sailing and i was able to add a new connection to my Visual Studio 2005 professional edition. I am using SQL Server Express Edition. I hope this helps. By default, the mentioned service was not turned on. I have now set it to automatic On everytime my machine boots up..Good luck..Thank u all for discussing ur problem and sharing the valuable information.|||

Euan: I have tried connecting every way that I can find, including:

1. Via the menu - "Tools\Connect to Database" which brings up the "Add Connection" Wizard.

2. Via Database Explorer, right click on Data Connections, and select "Add Connection"

3. Via Solution Explorer, right click on the project, and select "Add existing item" and go to the folder with the database file.

All these eventually end up with the same error message cited above.

If there is another way of connecting direclty to the database (i.e., without a file), please tell me the steps and I will be happy to try it.

I still am wondering about two of the questions I asked above:

1. If I am using Visual Basic 2005 Express, do I have to have SQL Server Express 2005 installed to connect to an .mdf database? I have two other machines with VB Express and SQL Server Express. No problems with either one and no problems with this machine when it had both express versions installed. It is only since I upgraded to the full SQL Server 2005 trial version that I am having problems with this machine when using VB Express. It seems that I have run into this compatibility question before with regard to user instances, etc.

2. If so, can SQL Server trial version and SQl Server Express 2005 be installed and run properly on the same machine? Then maybe VB Express could connect via SQL Server Express.

I have ordered the full version trial of Visual Studio (which I hope contains VB 2005) and I am hoping that it will be more compatible with the trial version of SQL Server.

Thanks for your patience in solving this.

|||

1/ Yes you need SQLExpress to connect to .mdfs, absed on your answer above where you list the services which are running, you have a default instance of regular sql server not of express right now so I suspect the file open thing is not going to work, you need to connect to it as a regular database, I don't have a copy of VS Express installed but there should be an option to connect via a database file(might just be called file) or database, you do not want the file option. You should be prompted for a server name in the correct connection type, just enter "."

2/ They can indeed be installed on the same machine but the trial version should just work for you.

sql

Error locating server/instance specified

I am trying to connect to the AdventureWorks database while using Visual Basic 2005 Express. I am currently using the SQL Server 2005 trial version. Here is the error message:

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: SQL Network Interfaces, Error: 26 - Error locating server/instance specified)

I found some threads in the archives when I researched this problem but couldn't relate the answers directly to my situation. Prior to installing SQL Server 2005 Trial version, I used the SQL Server 2005 Express edition on this machine and did not have any problems connecting to databases. I removed the express edition prior to installing the trial version.

In the Visual Basic "Add Connection" dialog box, I leave the default radio button checked ("Use Windows Authentication") as I have always done.

Any help in getting this resolved will be appreciated.

Use the Surface Area Configuration Tool to see if the server is able to accept connections.

In addition when you installed did you give the instance a name or did you leave it as the default?

|||

Hi Euan:

I installed the program using the default settings (which seemed to work fine for the Express version that I had used previously).

Following your suggestion, I opened up the Surface Area Configuration Tool and set all the items to "automatic" thinking that would allow the maximum access to the databases. Since I am only using it on one machine for evaluation, I am not worried about security at this point. I just want to get it to work with Visual Basic.

When I tried to connect to AdventureWorks in Visual Basic 2005 Express, I got the same error message as before.

Any thoughts on how to proceed?

|||

Is the SQL Server on the same machine as the VB code or on a different machine?

Can you please go into the Windows Services Control GUI from Control Panel and check the list of installed services, please list all the ones that start with mssql and say what their service status is.

What are you using as a connection string to the database(this might be in the property of a control so search the project for server=)

|||

VB and SQL Server are on the same machine.

I am using XP Home Edition. Here is what I found under Administrative Tools\Services:

SQL Server (MSSQLSERVER)Started

SQL Server AgentStarted

SQL Server Analysis Services (MSSQLSERVER)Started

SQL Server FullText Search (MSSQLSERVER)Started

I am attempting to connect via the menu - "Tools\Connect to Database" which brings up the "Add Connection" Wizard. There is to place to enter a connection string.

If I add a control such as the DataGridView and try to link it to a data source, I end up back at the "Add Connection" Wizard without being able to enter a connection string.

|||Can you please try conecting via sqlcmd and the command line please?|||

Thanks for your help Euan:

As a total Newbie, I am not familiar with using sqlcmd or the command prompt.After some reading in the MSDN books online I did the following:

I clicked “Start”

I clicked “Run”

I typed in “sqlcmd” and clicked “OK”

I typed in “select @.@.servername go” and clicked “Enter”

The program returned “Office” (1 row affected)

I assume that I connected to SQL Server 2005 using sqlcmd since “Office” is the server name I connect to with SQL Server Management Studio.

|||So when you try and connect from VS what connection string are you using?|||

As stated previously, I have been attempting to connect via the menu - "Tools\Connect to Database" which brings up the "Add Connection" Wizard. There is to place to enter a connection string. I have used the "Add Connection" Wizard previously with SQL 2005 Express to connect to several databases without any problems.

I have also tried via Database Explorer and Data Sources which have both eventually taken me to the same "Add Connection" Wizard resulting in the same error message.

I just tried something different that may help resolve this issue.

I tried adding the AdventureWorks database via Solution Explorer, right clicking the project and then add existing resource. I browsed to and clicked the AdventureWorks db and got the following error message:

Connections to SQL Server files (*.mdf) require SQL Server Express 2005 to function properly. Please verify the installation of the component or download from the URL: http://go.microsoft.com/fwlink/?LinkID=49251

I clicked OK to exit the message box and Solution Explorer then added AdventureWorks database to the project. But when I tried to connect as described above, I got the orignal error message about not locating the server.

Questions:

1. If I am using Visual Basic 2005 Express, do I have to have SQL Server Express 2005 installed to connect to an .mdf database?

2. If so, can SQL Server trial version and SQl Server Express 2005 be installed and run properly on the same machine?

3. Or is VB 2005E simply remembering that it had used SQL Server Express 2005 previously to connect to databases and is insisting on using it again instead of the SQL Server trial version?

|||The same exact thing happened with me. I am currently using visual basic 2005 express edition and SQL 2000. Everything seems to be working fine, but everytime i try to open a database using vb, it takes me to the exact same screen (where it asks me for the file path) and whether i want it to be a windows authentication or sql server. I tried both, and they give me the same error as well. Please let me know if someone knows how to solve this, my email address is shahkevat@.hotmail.com.|||Kevat, you are using a feature called user instances that is only available in SQL Server Express 2005, not SQL 2000. either connect to the database as a service (ie not a file) or install SQL Express|||

Moonshadow,

There are 2 ways of conencting to SQL Server I seem to remember one is file and one is database, I am guessing you are choosing file? Can you try using database please?

|||I had a problem with not being able to view my local server thru' Visual Studio 2005. Per the information on this thread, i saw the windows services under control panel -> Administrative tools on my windows XP professional box and turned on the service called "SQL Server Browser" which broadcasts the service from ur machine. (If i understand it correctly). After, that it was smooth sailing and i was able to add a new connection to my Visual Studio 2005 professional edition. I am using SQL Server Express Edition. I hope this helps. By default, the mentioned service was not turned on. I have now set it to automatic On everytime my machine boots up..Good luck..Thank u all for discussing ur problem and sharing the valuable information.|||

Euan: I have tried connecting every way that I can find, including:

1. Via the menu - "Tools\Connect to Database" which brings up the "Add Connection" Wizard.

2. Via Database Explorer, right click on Data Connections, and select "Add Connection"

3. Via Solution Explorer, right click on the project, and select "Add existing item" and go to the folder with the database file.

All these eventually end up with the same error message cited above.

If there is another way of connecting direclty to the database (i.e., without a file), please tell me the steps and I will be happy to try it.

I still am wondering about two of the questions I asked above:

1. If I am using Visual Basic 2005 Express, do I have to have SQL Server Express 2005 installed to connect to an .mdf database? I have two other machines with VB Express and SQL Server Express. No problems with either one and no problems with this machine when it had both express versions installed. It is only since I upgraded to the full SQL Server 2005 trial version that I am having problems with this machine when using VB Express. It seems that I have run into this compatibility question before with regard to user instances, etc.

2. If so, can SQL Server trial version and SQl Server Express 2005 be installed and run properly on the same machine? Then maybe VB Express could connect via SQL Server Express.

I have ordered the full version trial of Visual Studio (which I hope contains VB 2005) and I am hoping that it will be more compatible with the trial version of SQL Server.

Thanks for your patience in solving this.

|||

1/ Yes you need SQLExpress to connect to .mdfs, absed on your answer above where you list the services which are running, you have a default instance of regular sql server not of express right now so I suspect the file open thing is not going to work, you need to connect to it as a regular database, I don't have a copy of VS Express installed but there should be an option to connect via a database file(might just be called file) or database, you do not want the file option. You should be prompted for a server name in the correct connection type, just enter "."

2/ They can indeed be installed on the same machine but the trial version should just work for you.

Error installing SQL Server Management Studio Express

Yesterday I successfully installed Microsoft Visual Basic 2005 Express Edition which included SQL Server 2005 Express. Today I noticed I needed to download the Management Studio seperate download. I downloaded SQLServer2005_SSMSEE.msi and executed it and get the following error:

Error reading from file C:\...\SQLServer2005_SSMSEE.msi. Verify that the file exists and that you can access it..

Solved my own problem. Once I moved the msi to C:\ the installation worked. Apparently the path it was in was too long causing it to be unreadable. c:\xxxx\xxxx\SQLServer2005_SSMSEE.msiSQLServer2005_SSMSEE.msi.

Make sure you download the management tools for Express as well - it will make your life easier.

Buck Woody

Tuesday, March 27, 2012

Error installing SQL Server Management Studio Express

Yesterday I successfully installed Microsoft Visual Basic 2005 Express Edition which included SQL Server 2005 Express. Today I noticed I needed to download the Management Studio seperate download. I downloaded SQLServer2005_SSMSEE.msi and executed it and get the following error:

Error reading from file C:\...\SQLServer2005_SSMSEE.msi. Verify that the file exists and that you can access it..

Solved my own problem. Once I moved the msi to C:\ the installation worked. Apparently the path it was in was too long causing it to be unreadable. c:\xxxx\xxxx\SQLServer2005_SSMSEE.msiSQLServer2005_SSMSEE.msi.

Make sure you download the management tools for Express as well - it will make your life easier.

Buck Woody

sql

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 21, 2012

Error in sql management express installation

Hi,

I had earlier installation of microsoft sql server 2005 in my machine. Recently I installed the visual studio 2005 beta which comes with sql express and after going through many hoops(as it kept complaining about the previous installation of beta components) i was able to install it correctly. I was also able to also use visaul studio 2005 server explorer to connect to the SQLEXPRESS and create table etc... Now I wanted to install sql server management express so I downloaded SQLEXPR_ADV from te microsoft's website. During the installation it complained about the older version of SQL server management sutdio installed and hence could not install the sql server management express. By looking at different forums I found following steps to deinstall earlier version but still runs into this issue. I will really appreciate somebody's help....

STPES I FOLLOWED TO REMOVE EARLIER VERSION OF SQL SERVER 2005 MANAGEMENT STUDIO

Click Start, and then click Control Panel.
Double-click Add or Remove Programs.
In the list of installed programs, click Microsoft SQL Server 2005, and then click Change.
On the Component Selection page, select Workstation components, and then click Next.
Click Next.
On the Change or Remove Instance page, click Change Installed Components.
Expand Client Components, click Management Tools, and then select Entire Feature will be Unavailable. Or just select the entire client components
Click Next.
Click Install.

2) I also tried to use the complete uninstall of visual studio ( By using the tolls

vs_unists_betas.exe) and after that also window uninstall clean up (msiccu2)

and then reinstalling visual studio 2005 beta which would install sql express...But

nothing seems to be able to uninstall the previous version of SQL SERVER 2005

Management studio from my computer and hence I am not able to uninstall the

sql server management express.

hi,

try having a look at http://forums.microsoft.com/MSDN/ShowPost.aspx?PostID=907736&SiteID=1 as well

regards

sql

Wednesday, March 7, 2012

Error in INSERT INTO

Hi,
I'm sure that this is quite a simple program. I am generating an INSERT INTO statement in the Query builder (!) of Visual Basic .NET, and I consistantly get the following error: "Missing semi-colon at the end of the end of the SQL statement." The SQL stat
ement in question is:
INSERT INTO tblBlocks
(ActualTotalHoles, Block_Name, BlockComment, ChargedHoles, PlannedTotalHoles, Site_Name)
VALUES (?, ?, ?, ?, ?, ?)
SELECT tblBlocks.Block_Name, tblBlocks.Site_Name
FROM tblBlocks
WHERE (tblBlocks.Block_Name =?),( tblBlocks.Site_Name = ?);
Would much appreciate some help - Thanks.
It's being interpreted as two SQL statements, not one. The missing
semi-colon should come after VALUES(?, ?, ?, ?, ?, ?);
"Lite" <anonymous@.discussions.microsoft.com> wrote in message
news:C052EA2E-9424-4E0C-9D30-8FAFC93F064B@.microsoft.com...
> Hi,
> I'm sure that this is quite a simple program. I am generating an INSERT
INTO statement in the Query builder (!) of Visual Basic .NET, and I
consistantly get the following error: "Missing semi-colon at the end of the
end of the SQL statement." The SQL statement in question is:
> INSERT INTO tblBlocks
> (ActualTotalHoles, Block_Name, BlockComment,
ChargedHoles, PlannedTotalHoles, Site_Name)
> VALUES (?, ?, ?, ?, ?, ?)
> SELECT tblBlocks.Block_Name, tblBlocks.Site_Name
> FROM tblBlocks
> WHERE (tblBlocks.Block_Name =?),( tblBlocks.Site_Name = ?);
> Would much appreciate some help - Thanks.

Error in INSERT INTO

Hi,
I'm sure that this is quite a simple program. I am generating an INSERT INTO
statement in the Query builder (!) of Visual Basic .NET, and I consistantly
get the following error: "Missing semi-colon at the end of the end of the S
QL statement." The SQL stat
ement in question is:
INSERT INTO tblBlocks
(ActualTotalHoles, Block_Name, BlockComment, ChargedHoles, PlannedTotalHoles
, Site_Name)
VALUES (?, ?, ?, ?, ?, ?)
SELECT tblBlocks.Block_Name, tblBlocks.Site_Name
FROM tblBlocks
WHERE (tblBlocks.Block_Name =?),( tblBlocks.Site_Name = ?);
Would much appreciate some help - Thanks.It's being interpreted as two SQL statements, not one. The missing
semi-colon should come after VALUES(?, ?, ?, ?, ?, ?);
"Lite" <anonymous@.discussions.microsoft.com> wrote in message
news:C052EA2E-9424-4E0C-9D30-8FAFC93F064B@.microsoft.com...
> Hi,
> I'm sure that this is quite a simple program. I am generating an INSERT
INTO statement in the Query builder (!) of Visual Basic .NET, and I
consistantly get the following error: "Missing semi-colon at the end of the
end of the SQL statement." The SQL statement in question is:
> INSERT INTO tblBlocks
> (ActualTotalHoles, Block_Name, BlockComment,
ChargedHoles, PlannedTotalHoles, Site_Name)
> VALUES (?, ?, ?, ?, ?, ?)
> SELECT tblBlocks.Block_Name, tblBlocks.Site_Name
> FROM tblBlocks
> WHERE (tblBlocks.Block_Name =?),( tblBlocks.Site_Name = ?);
> Would much appreciate some help - Thanks.

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.

Error in executing a DTS Package from Visual Basic

Hi! Good Day!

I am executing a DTS PAckage from Visual Basic. My code is this:

objPackage.LoadFromSQLServer "SERVER", , , _
DTSSQLStgFlag_UseTrustedConnection, , , , "DTSPackage1"
objPackage.Execute

objPackage.LoadFromSQLServer "SERVER", , , _
DTSSQLStgFlag_UseTrustedConnection, , , , "DTSPackage2"
objPackage.Execute

The first DTS package was executed successfully, but when it hit the second package, an error occurs:

Step 'DTSStep_DTSDataPumpTask_1' already exists in the collection.

Please help.
Thanks.hi

try this

dim objPackage as DTS.Package

set objPackage = new DTS.Package
objPackage.LoadFromSQLServer "SERVER", , , _
DTSSQLStgFlag_UseTrustedConnection, , , , "DTSPackage1"
objPackage.Execute

set objPackage = nothing

set objPackage = new DTS.Package

objPackage.LoadFromSQLServer "SERVER", , , _
DTSSQLStgFlag_UseTrustedConnection, , , , "DTSPackage2"
objPackage.Execute

hope this will solve the problem|||Hi baburajv,

My DTS packages are working well now.
Thank you so much for your help.

God bless :)