Showing posts with label searched. Show all posts
Showing posts with label searched. Show all posts

Thursday, March 22, 2012

Create a Mobile database on desktop

I have searched through this forum and the news group

microsoft.public.sqlserver.ce

for this topic. I only find a post from Darren Shaffer and I requested a document.

Unfortunately, there is not a clear example of how to create a mobile database (sdf) on a desktop machine which contains VS 2005 and SQL server 2005 by using Visual Basic 2005.

I am sure a clear example in VB for this problem would help a lot of people. Hence anybody who knows how to perform this task, Please help these people.

Thanks in advance

TalatAfter a little bit of search, I succeeded! Here is the guidelines for using an SQL server mobile dataset residing in your desktop computer on your desjktop (populating a SQL Server mobile database on your desktop). At the end of the guidelines, I give a sample program to populate an sqlce database from a text file.

I hope you will find these guidelines and sample program usefull.

You may contact me at toncu@.nospam.e-kolay.net (remove nospam for actual address)

1. create a Windowsapplication project
File->New Project
Choose Windows in Project Types and Windows Apllication from Templates

2. Insert a reference to SQL Server Mobile
Project->Add Reference->Browse
c:\Program Files\Microsoft Visual Studio 8
\Common7\IDE\System.Data.SqlServerCE.DLL

3. Insert
imports system.data.sqlserverce
at the top of your form file

4. Write your application just as you would as if your project was a Smartdeviceapplication.

i.e. use sqlconnection and other constructs.

A sample application is as follows:
(dbtableexist is a subroutine which shows how to process the SCHEMA.
In this subroutine, change TABLES to INDEXES and TABLE_NAME to INDEX_NAME to search for an index)

Imports system.data.SqlServerCe
Imports System.IO
Public Sub createaccessfile(ByVal a$)
'curdbpath is the path of the database e.g. d:\my sql databases\
Dim connStr As String = "Data Source = " & curdbpath & a$ & ".sdf"
Dim conn As SqlCeConnection = Nothing
Dim command As SqlCeCommand
Try
conn = New SqlCeConnection(connStr)
conn.Open()
command = conn.CreateCommand()
If dbtableexist(conn, "ACCESSFILE") Then
command.CommandText = "DROP TABLE ACCESSFILE"
command.ExecuteNonQuery()
End If
command.CommandText = "CREATE TABLE ACCESSFILE ( code nchar(20),field nchar(3),totalrecs nvarchar(255),indexbits ntext)"
command.ExecuteNonQuery()
command.CommandText = "CREATE INDEX codeindex on ACCESSFILE (field,code)"
command.ExecuteNonQuery()
Catch ex As SqlCeException
Dim m1 = ex.Message
Dim m2 = ex.Source
Dim m3 = ex.NativeError
MsgBox(m1 & m2 & m3, , "open " & a$ & " for accessfile creation")
Exit Sub
End Try

' Create and prepare a SQL statement.
command.CommandText = " insert into accessfile values (?,?,?,?);"

' Read and insert the lines from the file until the end
' of the file is reached.
Dim accfname As String = curdbpath & a$ & "_accessfile.inp"
Dim fs As FileStream = New FileStream(accfname, FileMode.Open)
Dim sr As New StreamReader(fs)
Dim line As String, codestr As String, fieldstr As String, totalrecsstr As String, indexbitsstr As String
Dim line1 As String, flagstr As String, field As Integer

line = sr.ReadLine : line1 = line
Dim currec As Integer = 0
' Note: Even though named parameterized queries are not supported, we still need
' to provide unique parameter names so that we can manipulate parameter collection;
command.Parameters.Add("@.code", "a")
command.Parameters.Add("@.field", 1)
command.Parameters.Add("@.totrecs", "c")
command.Parameters.Add("@.indexbits", "d")
Do
currec = currec + 1
If currec Mod 10 = 0 Then dispcaption(Str(currec))
flagstr = before(line, Chr(9)) : line = after(line, Chr(9))
codestr = before(line, Chr(9)) : line = after(line, Chr(9))
field = Val(before(line, Chr(9))) : line = after(line, Chr(9))
totalrecsstr = before(line, Chr(9)) : line = after(line, Chr(9))
indexbitsstr = line
Try
command.Parameters(0).Value = codestr
command.Parameters(1).Value = Format(field, "000")
command.Parameters(2).Value = totalrecsstr
command.Parameters(3).Value = indexbitsstr
' Calling Prepare after having set the Commandtext and parameters.
command.Prepare()
command.ExecuteNonQuery()
Catch ex As SqlCeException
Dim m1 = ex.Message
Dim m2 = ex.Source
Dim m3 = ex.NativeError
MsgBox(m1 & m2 & m3, , "Add record to Acessfile")
conn.Close()
sr.Close()
Exit Sub
End Try
line = sr.ReadLine : line1 = line
Loop Until line Is Nothing
sr.Close()
conn.Close()
End Sub
Private Function dbtableexist(ByVal dbconnection As SqlCeConnection, ByVal tablename As String) As Boolean
Dim cmd As SqlCeCommand, rdr As SqlCeDataReader
Dim iname As String, tablename1 As String, i As Integer
tablename1 = UCase(tablename)
cmd = dbconnection.CreateCommand
cmd.CommandType = CommandType.Text
cmd.CommandText = "select * from INFORMATION_SCHEMA.INDEXES"
Try
rdr = cmd.ExecuteReader
Catch ex As SqlCeException
Dim m1 = ex.Message
Dim m2 = ex.Source
Dim m3 = ex.NativeError
MsgBox(m1 & m2 & m3)
Stop
End Try
Do While rdr.Read
iname = rdr("TABLE_NAME")
If UCase(iname) = tablename1 Then dbtableexist = True : Exit Function
Loop
dbtableexist = False
End Function

Sunday, March 11, 2012

CR 8.5 - (almost) blank first page

Hi,

Having a problem with crystal reports 8.5 (from within VB6). searched and searched, to no avail, so now I post... :)

i have a report with the following layout:
-Report header
-Page header
-Group header 1
-detail
-group footer 1
-page footer
-report footer

Problem is, if group 1 will not fit on the first page of the report, then the first page will print with only the report header and report footer on it - nothing else.

I've tried unchecking all the "Keep together" options on the sections but it doesn't change a thing. any advice people? i found an article talking about this problem and how V10 fixes it, but surely there is a workaround (or at least something). Frankly, I don't care if it puts half a section on a page if it will fit complete on the next - i just don't want this silly blank first page printing.Have you remembered checking off the Keep Group together option in both the Change Group Options and Format Section Menues? Doing this for all groups has worked for me this far.

- Jukka|||Great stuff - it works. Thanks heaps for actually finding this post and replying to it. I'd given up!

Sunday, February 19, 2012

Countries & Cities Tables

I need to have tables of world countries and cities to use in a user registration form, I searched the Internet for scripts,xml,excel files for countries & cities lists but I couldn't find. Can anybody tell me where to get them from?

Hello my friend,

Let me introduce you to a website I used to worked on that has plenty of this information: -

http://www.wshtravel.com/travel_guides

Kind regards

Scotty

|||

Thanks but the link is not workingSad

|||

I think that if you will try to do something like this on your page it will be very slow and very big, so maybe just use countries. You can try to get countries fromwww.usps.com just try to send pckage to international destination and you will get drop down list with countries to which USPS delivers packages. You can also trywww.UPS.com maybe they have also cites?

Thanks

JPazgier

Counting total number of queries executed within the page

Hi everyone,

Does exist an easy way to count the actually number of queries executed within a page?

I've searched here and in google but found anything...

Thanks in advance!

If SQL Server is your backend database, you can use SQL Profiler to run a trace on the statements executed.

|||

The db is sql server 2000, but it's on a shared server.. can I use the profiler in a shared environment too?

In case I can use it, does it aggregate someqhat the queries per ASP.NET page executed?

Thanks!

|||

>can I use the profiler in a shared environment too?
You can limit it by database.

>In case I can use it, does it aggregate someqhat the queries per ASP.NET page executed?
Given the right option it will report each query run.