Showing posts with label conn. Show all posts
Showing posts with label conn. Show all posts

Tuesday, March 27, 2012

getting the database collection doesnt always wrok

why doesn't this code always work?

<code>

Dim conn as serverconnection=New serverconnection(".\SQLEXPRESS")

Dim srv as new server(conn)

Dim db as database

for each db in srv.databases

cmbDBfilenames.items.add(db.Name.tostring)

Next

</code)

If the databases are located in the applicatio path , it doesn't pick them up


Hi,

The method you are using only checks for the server attached databases not the user instances. So if the database is in the application path, but SQL Server does not hold an actual reference to them (being attached to the databases) you won′t find them (SMO makes a call to the server to evaluate the available databases)


HTH, Jens K. Suessmeyer.


http://www.sqlserver2005.de

sql

Monday, March 12, 2012

Getting RecordCount with TableDirect

Hi, I would like to know if there's any method to get the total number of records in a table without using query. I have the following codes.



Dim conn As SqlServerCe.SqlCeConnection
Dim cmd As SqlServerCe.SqlCeCommand
Dim rdr As SqlServerCe.SqlCeDataReader

conn = New SqlServerCe.SqlCeConnection("Data source=\My Documents\test.sdf")
conn.Open()

cmd = New SqlServerCe.SqlCeCommand("Staff_Table", conn)
cmd.CommandType = CommandType.TableDirect
cmd.IndexName = "Id_Ind"

rdr = cmd.ExecuteReader
rdr.Seek(SqlServerCe.DbSeekOptions.FirstEqual, int_seek_n)

If rdr.Read() Then
strResult = rdr.GetString(1)
End If

rdr.Close()
conn.Close()

I did quite a bit of searching and got no results. Thanks.No, there's no shortcut to getting the count of rows in a table. I recommend doing a SELECT COUNT(*) and use ExecuteScalar to get the best performance on this query.

-Darren Shaffer|||Thanks Darren. Looks like I have no other choice. :)