SQL Server CE problem

Z

Zahid

Hi,

the following code always throws the exception. Why? It
should simply create the table with the two rows:


If Not System.IO.File.Exists("\Program
files\testSQLCE\MyDB.sdf") Then
Dim sqlEngine As New
SqlCeEngine("Data Source = \Program
files\testSQLCE\MyDB.sdf")
sqlEngine.CreateDatabase()
gSqlEngine = sqlEngine

Try
Dim myConnectionString As String =
"Data Source =\Program
files\testSQLCE\MyDB.sdf;"

Dim myConnection As New SqlCeConnection
(myConnectionString)
Dim myCreateQuery As String
myCreateQuery = "CREATE TABLE Products
(PLU INTEGER NOT NULL,
Description VARCHAR(40) DEFAULT 'Description' NOT
NULL" _
& ", V$ATpos INTEGER DEFAULT 0 NOT NULL)"

Dim myCommand As New SqlCeCommand(myCreateQuery)
myCommand.Connection = myConnection

myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()


Catch oExcept As Exception
MessageBox.Show(oExcept.Message, _
"is thrown as Exception - z")
End Try

Else
MsgBox("Database Already Exists")
End If


Thanks in advance.
 
K

Kevin Boske - [MS]

Hi Zahid,

You should use the ShowErrors() function as described in the Books Online
to get more detail about the exception. The exception is being thrown
because you are attempting to create a Varchar column. SQL Server CE only
supports Unicode datatypes. Change it to nvarchar and should work.

Kevin Boske
([email protected])
SQL Server CE Team
Microsoft
----------------------------------------------------------------------------
----------------------------------------
Everything you need to know about SQL Server CE:

http://www.microsoft.com/sql/ce/techinfo/default.asp
----------------------------------------------------------------------------
----------------------------------------
This posting is provided "AS IS" with no warranties, and confers no rights.
Use of included script samples are subject to the terms specified at
http://www.microsoft.com/info/cpyright.htm.
----------------------------------------------------------------------------
----------------------------------------
--------------------
Content-Class: urn:content-classes:message
From: "Zahid" <[email protected]>
Sender: "Zahid" <[email protected]>
Subject: SQL Server CE problem
Date: Tue, 26 Aug 2003 06:07:01 -0700
Lines: 47
Message-ID: <[email protected]>
MIME-Version: 1.0
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
X-Newsreader: Microsoft CDO for Windows 2000
X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4910.0300
Thread-Index: AcNr0vAkEYygFyxKSrCDJQ0/9/3KrA==
Newsgroups: microsoft.public.dotnet.framework.compactframework
Path: cpmsftngxa06.phx.gbl
Xref: cpmsftngxa06.phx.gbl
microsoft.public.dotnet.framework.compactframework:32016
NNTP-Posting-Host: TK2MSFTNGXA09 10.40.1.161
X-Tomcat-NG: microsoft.public.dotnet.framework.compactframework

Hi,

the following code always throws the exception. Why? It
should simply create the table with the two rows:


If Not System.IO.File.Exists("\Program
files\testSQLCE\MyDB.sdf") Then
Dim sqlEngine As New
SqlCeEngine("Data Source = \Program
files\testSQLCE\MyDB.sdf")
sqlEngine.CreateDatabase()
gSqlEngine = sqlEngine

Try
Dim myConnectionString As String =
"Data Source =\Program
files\testSQLCE\MyDB.sdf;"

Dim myConnection As New SqlCeConnection
(myConnectionString)
Dim myCreateQuery As String
myCreateQuery = "CREATE TABLE Products
(PLU INTEGER NOT NULL,
Description VARCHAR(40) DEFAULT 'Description' NOT
NULL" _
& ", V$ATpos INTEGER DEFAULT 0 NOT NULL)"

Dim myCommand As New SqlCeCommand(myCreateQuery)
myCommand.Connection = myConnection

myConnection.Open()
myCommand.ExecuteNonQuery()
myCommand.Connection.Close()


Catch oExcept As Exception
MessageBox.Show(oExcept.Message, _
"is thrown as Exception - z")
End Try

Else
MsgBox("Database Already Exists")
End If


Thanks in advance.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top