i am having trouble in creating new database using SQL CE

A

alexoh84

hi,

i am new to SQL CE. i am trying to create a new database n i doesn't
seem to work. this is my code which i copy from msdn.com for testing
purposes n it dun work as well.

Dim SQLEngine As SqlCeEngine
SQLEngine = New SqlCeEngine("data source=c:\test.sdf")
SQLEngine.CreateDatabase()

sql = "CREATE TABLE ADR_ADDRESS ( "
sql &= "Address_ID INT IDENTITY(1,1) PRIMARY KEY "
sql &= ",Name nvarchar(50) "
sql &= ",Address ntext "
sql &= ",Telephone ntext "
sql &= ",Last_Edited datetime "
sql &= ",IsPrivate_Flag nvarchar(10) "
sql &= ")"

Dim objConn As New SqlCeConnection

objConn.ConnectionString = "data source=c:\test.sdf"
objConn.Open()



Dim objCmd As SqlCeCommand = New SqlCeCommand(sql, objConn)
objCmd.CommandType = Data.CommandType.Text
objCmd.ExecuteNonQuery()
objCmd.Dispose()

it gave me an error when running saying that the path is invalid. i
even try to manually create the database n try to connect to it n it
still came up with the same error. need help figuring out why.. thanks
 
A

Alejandro Mezcua

I assume you are trying to run this code on a CE device or a CE emulator. If
so, the path you are trying to use is not valid, there is no C: drive on a
CE device. You can try using "data source=\test,sdf" as the connection
string to create the database file on the root folder of the device.

Cheers,

Alejandro Mezcua
MVP .NET Compact Framework
http://www.byteabyte.net/
 
A

alexoh84

icic..thanks for the info. really appreciate it. but if that is the
case, then how would i able to connect to a databse which reside in my
PC? is there anyway to do that or that i am unable to do that ?
 
G

Guest

You can't through SqlCe. You can make a direct connection to a full SQL
Server of a network connection.

-Chris
 

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