Showing posts with label path. Show all posts
Showing posts with label path. Show all posts

Wednesday, March 7, 2012

HELP: SqlCeConnection path error in .NET compact framework (Pocket PC Emulator)

Hi all,

I am trying to access my SQL Server database through SqlCeConnection:

cecon = new SqlCeConnection("Data Source=D:\\D_Drive\\csharppract\\nddbpda\\nddbpda\\nddbpdadatabase.sdf");
cecon.Open();


I am getting the following error:

System.Data.SqlServerCe.SqlCeException was unhandled
Message="The path is not valid. Check the directory for the database. [ Path = D:\\D_Drive\\csharppract\\nddbpda\\nddbpda\\nddbpdadatabase.sdf ]"
HResult=-2147467259
NativeError=25009
Source="SQL Server 2005 Mobile Edition ADO.NET Data Provider"
StackTrace:
at System.Data.SqlServerCe.SqlCeConnection.ProcessResults()
at System.Data.SqlServerCe.SqlCeConnection.Open()
at System.Data.SqlServerCe.SqlCeConnection.Open()
at nddbpda.frmCeMain.frmCeMain_Load()
at System.Windows.Forms.Form.OnLoad()
at System.Windows.Forms.Form._SetVisibleNotify()
at System.Windows.Forms.Control.set_Visible()
at System.Windows.Forms.Application.Run()
at nddbpda.Program.Main()


When I tried to get the path from which the database file is being accepted, I got a different path:

string path;
path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
MessageBox.Show(path);

This code gives me this path:

\Program Files\nddbpda


Then I changed the path in my connection string to this:

cecon = new SqlCeConnection("Data Source=\\Program Files\\nddbpda\\nddbpdadatabase.sdf");
cecon.Open();


When I ran my application it worked (virtually), but the database is not getting updated (for obvious reasons).

What should I do now to correct this?

Thanks in advance.

Saswata.

Did you ever find an answer to your problem? I am experiencing the very same thing.

If I reference a local sdf it works fine, but if I reference the sdf located on the CE device, I get the same error as you.
|||

Windows CE devices (including emulator – simulated device) don't support drive letters (see that "D:\" in the path above? That makes it invalid on CE), don't support relative paths (that is, all paths must be full and absolute) and can't see your desktop hard drive (not by drive letter anyway). Common way to get absolute path is to append database name to the path to the application itself as done above.

Naturally, database on desktop won’t be updated because device has no idea it even exists. It changes database on device file system and it’s up to you to copy changed database from device file system to desktop file system as needed.

Now to using database on device from desktop application: that won’t work because there’s no way to reference database on device in desktop application; device is not mapped as desktop file system. Active Sync explorer extension simply fakes it. Visual Studio does that via special remote provider which is not public. If you want to access database on device then copy it to local file system (e.g. using RAPI), access it, and then copy it back to device. See this.

|||

If u got any soln on above please share this wiht me

My ID is abhijeettidke@.gmail.com

Monday, February 27, 2012

HELP: SqlCeConnection path error in .NET compact framework (Pocket PC Emulator)

Hi all,

I am trying to access my SQL Server database through SqlCeConnection:

cecon = new SqlCeConnection("Data Source=D:\\D_Drive\\csharppract\\nddbpda\\nddbpda\\nddbpdadatabase.sdf");

cecon.Open();

I am getting the following error:

System.Data.SqlServerCe.SqlCeException was unhandled
Message="The path is not valid. Check the directory for the database. [ Path = D:\\D_Drive\\csharppract\\nddbpda\\nddbpda\\nddbpdadatabase.sdf ]"
HResult=-2147467259
NativeError=25009
Source="SQL Server 2005 Mobile Edition ADO.NET Data Provider"
StackTrace:
at System.Data.SqlServerCe.SqlCeConnection.ProcessResults()
at System.Data.SqlServerCe.SqlCeConnection.Open()
at System.Data.SqlServerCe.SqlCeConnection.Open()
at nddbpda.frmCeMain.frmCeMain_Load()
at System.Windows.Forms.Form.OnLoad()
at System.Windows.Forms.Form._SetVisibleNotify()
at System.Windows.Forms.Control.set_Visible()
at System.Windows.Forms.Application.Run()
at nddbpda.Program.Main()

When I tried to get the path from which the database file is being accepted, I got a different path:

string path;

path = System.IO.Path.GetDirectoryName(

System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);

MessageBox.Show(path);

This code gives me this path:

\Program Files\nddbpda

Then I changed the path in my connection string to this:

cecon = new SqlCeConnection("Data Source=\\Program Files\\nddbpda\\nddbpdadatabase.sdf");

cecon.Open();

When I ran my application it worked (virtually), but the database is not getting updated (for obvious reasons).

What should I do now to correct this?

Thanks in advance.

Saswata.

Moving to SQL Server Compact Edition forum where it has got better chances of being answered.

-Thanks,

Mohit

|||You can only access files located on the emulator, not your local drives. You have to copy or create the sdf file in the emulator in the desired location. There is no C: drive or D: drive in the emulator, just a "\" root

HELP: SqlCeConnection path error in .NET compact framework (Pocket PC Emulator)

Hi all,

I am trying to access my SQL Server database through SqlCeConnection:

cecon = new SqlCeConnection("Data Source=D:\\D_Drive\\csharppract\\nddbpda\\nddbpda\\nddbpdadatabase.sdf");
cecon.Open();


I am getting the following error:

System.Data.SqlServerCe.SqlCeException was unhandled
Message="The path is not valid. Check the directory for the database. [ Path = D:\\D_Drive\\csharppract\\nddbpda\\nddbpda\\nddbpdadatabase.sdf ]"
HResult=-2147467259
NativeError=25009
Source="SQL Server 2005 Mobile Edition ADO.NET Data Provider"
StackTrace:
at System.Data.SqlServerCe.SqlCeConnection.ProcessResults()
at System.Data.SqlServerCe.SqlCeConnection.Open()
at System.Data.SqlServerCe.SqlCeConnection.Open()
at nddbpda.frmCeMain.frmCeMain_Load()
at System.Windows.Forms.Form.OnLoad()
at System.Windows.Forms.Form._SetVisibleNotify()
at System.Windows.Forms.Control.set_Visible()
at System.Windows.Forms.Application.Run()
at nddbpda.Program.Main()


When I tried to get the path from which the database file is being accepted, I got a different path:

string path;
path = System.IO.Path.GetDirectoryName(
System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase);
MessageBox.Show(path);

This code gives me this path:

\Program Files\nddbpda


Then I changed the path in my connection string to this:

cecon = new SqlCeConnection("Data Source=\\Program Files\\nddbpda\\nddbpdadatabase.sdf");
cecon.Open();


When I ran my application it worked (virtually), but the database is not getting updated (for obvious reasons).

What should I do now to correct this?

Thanks in advance.

Saswata.

Did you ever find an answer to your problem? I am experiencing the very same thing.

If I reference a local sdf it works fine, but if I reference the sdf located on the CE device, I get the same error as you.
|||

Windows CE devices (including emulator – simulated device) don't support drive letters (see that "D:\" in the path above? That makes it invalid on CE), don't support relative paths (that is, all paths must be full and absolute) and can't see your desktop hard drive (not by drive letter anyway). Common way to get absolute path is to append database name to the path to the application itself as done above.

Naturally, database on desktop won’t be updated because device has no idea it even exists. It changes database on device file system and it’s up to you to copy changed database from device file system to desktop file system as needed.

Now to using database on device from desktop application: that won’t work because there’s no way to reference database on device in desktop application; device is not mapped as desktop file system. Active Sync explorer extension simply fakes it. Visual Studio does that via special remote provider which is not public. If you want to access database on device then copy it to local file system (e.g. using RAPI), access it, and then copy it back to device. See this.

|||

If u got any soln on above please share this wiht me

My ID is abhijeettidke@.gmail.com

Help: Shortest Path in sql

Hello to all,

help, help,...

i have with this problem since 3 weeks, until now i cann't resolve this problem. Maybe can somebody help me. I am hopeless.Crying

i have a data table ValidRelationship, i will check if there is a relationship between two members by this table.

datas in the table ValidRelationship:

IDMember IDOtherMember IDType

3700

372610000372637001000037423672100003672374210000342235481000035483422100003548371710000371735481000036753695100003695367510000

I will give two member and check their Relationship with a sql query. but it can be that this two member have no relationship. So i define here that man should search processor <= 6 . To better describe i use a example: max. Result of this query is: 1-2-3-4-5-6. If this is a relationship between 1-7 is 1-2-3-4-5-6-7, but i will give a answer that this is no relationship between 1-7. because processor > 6.

But my problem is: this query executing is too slow. if i habe two member no relationship, the time of this complete sql query to execute is more than 1 minutes. Is my algorithm wrong, or where is the problem, why this executing is so slow? How can i quickly get the relationships between two member, if my algorithms is not right? The following Query is only to processor = 3, but it works too slowly, so i don't write remaining processors.

declare @.IDMint;

declare @.IDOint;

set @.IDM= 3418;

set @.IDO= 4270

selecttop 1 IDMember

from v_ValidRelationships

where IDMember= @.IDM

and @.IDOin(select a.IDOtherMemberfrom v_ValidRelationshipsas awhere a.IDMember= @.IDM)

selecttop 1 a.IDMember, b.IDMember

from v_ValidRelationshipsas a, v_ValidRelationshipsas b

where a.IDMember= @.IDM

and b.IDMemberin(select c.IDOtherMemberfrom v_ValidRelationshipsas cwhere c.IDMember= @.IDM)

and @.IDOin(select d.IDOtherMemberfrom v_ValidRelationshipsas dwhere d.IDMember= b.IDMember)

selecttop 1 a.IDMember, b.IDMember, e.IDMember

from v_ValidRelationshipsas a, v_ValidRelationshipsas b, v_ValidRelationshipsas e

where a.IDMember= @.IDM

and b.IDMemberin(select c.IDOtherMemberfrom v_ValidRelationshipsas cwhere c.IDMember= @.IDM)

and e.IDMemberin(select f.IDOtherMemberfrom v_ValidRelationshipsas fwhere f.IDMember= b.IDMember)

and @.IDOin(select d.IDOtherMemberfrom v_ValidRelationships as d where d.IDMembe = e.IDMember)

If someone has a idea, please help me. Thank a million

Best Regards

Shasha

The reason it starts gumming up is because you are potentially creating millions of records for this process - in step one, you are only scanning the records in the table, but then you're exponentially scanning the table - like this example with just 10 rows:

1) Look for relationship in 10 rows

2) Look for relationship in 10 x 10 rows (100)

3) Look for relationship in 10 x 10 x 10 rows (1000)

4) Look for relationship in 10 x 10 x 10 x 10 rows (10,000)

5) 100,000

6) 1,000,000

You would have to totally revisit the structure to avoid this.

|||

Hello Sohnee,

I'm sorry that i can not good understand what you mean. Could you please explain more some details? Thank you very much.

Regards

Shasha

|||

Sorry, I don't have time to write the exact query, but perhaps someone else here wants to take a shot.

Assuming the that IDMember is "parent", and IDOtherMember is "child". Build a recursive CTE, that returns all the children of the parent up to x levels deep (columns parent,child,path_from_parent_to_child,depth).

Then using the CTE, filter only the rows where parent is equal to an input parameter, child is equal to an input parameter, and depth is equal to or less than an input parameter.

|||

@.MaxDepth determines the "number of processors". If you want to search up to 7 deep, set @.MaxDepth to 7. The results are not exactly the same, but similiar enough. The Path column will include a comma delimited list of ID's it went through to reach the other member.

DECLARE @.MaxDepthint

DECLARE @.IDMemberint

DECLARE @.IDOtherMemberint

SET @.MaxDepth=10

SET @.IDMember=3700

SET @.IDOtherMember=3726

WITH DirectReports(IDMember, IDOtherMember,Path, Depth)

AS

(

-- Anchor member definition

SELECT IDMember, IDOtherMember,','+CAST(IDMemberasvarchar(MAX))+','+CAST(IDOtherMemberASvarchar(MAX))+','ASPath, 1AS Depth

FROM ValidRelationship

WHERE IDMember=@.IDMember

UNIONALL

-- Recursive member definition

SELECT t2.IDMember, t1.IDOtherMember, t2.Path+CAST(t1.IDOtherMemberASvarchar(MAX))+','ASPath, Depth+ 1

FROM ValidRelationship t1

INNERJOIN DirectReportsAS t2ON t2.IDOtherMember= t1.IDMember

WHERECHARINDEX(','+CAST(t1.IDOtherMemberASVARCHAR(MAX))+',',t2.Path,0)=0

AND t2.Depth<@.MaxDepth

)

-- Statement that executes the CTE

SELECTTOP 1 IDMember,IDOtherMember,SUBSTRING(Path,2,LEN(path)-2),Depth

FROM DirectReports

WHERE IDOtherMember=@.IDOtherMember

ORDERBY DepthDESC

|||

I changed the query from what I described above so that it won't allow circular paths (3700,3726,3700, etc) because they will never be "shortest", and also to reduce processing time.

I also implemented the MaxDepth differently. Instead of allowing the CTE to recurse completely and then filtering based on the depth, I terminate the recursion at the MaxDepth.

|||

hello to motly,

Thank you very much. With your help i have resolved this problem. Now i can quickly get a result. Thanks

Best Regard

Shasha

Sunday, February 19, 2012

HELP...Splitting a string in T-SQL

I have a situation where I am querying the master.dbo.sysaltfiles to return
the path to the datafiles. What I am really interested in is the path...not
the filenames.
Example:
select @.DataPath = FileName From master.dbo.sysaltfiles WHERE name =
@.CurrentDB
This returns: M:\Microsoft SQL Server\CurrentDB.mdf
What I need is just the path:
Example:
M:\Microsoft SQL Server\
I was looking for something like VB's split string or something to remove
the filename.
What can I do to achieve the desired result?
Thanks!
RonThere are plenty of string functions in T-SQL that will help with this.
Check out REVERSE, CHARINDEX and SUBSTRING.
"RSH" <way_beyond_oops@.yahoo.com> wrote in message
news:%23Yp4navNGHA.2884@.TK2MSFTNGP12.phx.gbl...
> I have a situation where I am querying the master.dbo.sysaltfiles to
> return the path to the datafiles. What I am really interested in is the
> path...not the filenames.
> Example:
> select @.DataPath = FileName From master.dbo.sysaltfiles WHERE name =
> @.CurrentDB
> This returns: M:\Microsoft SQL Server\CurrentDB.mdf
>
> What I need is just the path:
> Example:
> M:\Microsoft SQL Server\
> I was looking for something like VB's split string or something to remove
> the filename.
> What can I do to achieve the desired result?
>
> Thanks!
> Ron
>|||Excellent. If possible could you give me a sample of how to use them to
achieve what I'm going for?
Thanks,
Ron
"Aaron Bertrand [SQL Server MVP]" <ten.xoc@.dnartreb.noraa> wrote in message
news:OY9JLgvNGHA.3984@.TK2MSFTNGP14.phx.gbl...
> There are plenty of string functions in T-SQL that will help with this.
> Check out REVERSE, CHARINDEX and SUBSTRING.
>
> "RSH" <way_beyond_oops@.yahoo.com> wrote in message
> news:%23Yp4navNGHA.2884@.TK2MSFTNGP12.phx.gbl...
>|||Here is an example
declare @.c varchar(50)
select @.c ='M:\Microsoft SQL Server\CurrentDB.mdf'
select left(@.c,(len(@.C) -CHARINDEX('',reverse(@.c)))+1)
Just replace @.c with your field name
http://sqlservercode.blogspot.com/|||Thank you so much!
I'm under the gun so I needed to "learn" quickly. I appreciate your help!
Ron
"SQL" <denis.gobo@.gmail.com> wrote in message
news:1140535404.793871.132130@.g47g2000cwa.googlegroups.com...
> Here is an example
> declare @.c varchar(50)
> select @.c ='M:\Microsoft SQL Server\CurrentDB.mdf'
> select left(@.c,(len(@.C) -CHARINDEX('',reverse(@.c)))+1)
> Just replace @.c with your field name
> http://sqlservercode.blogspot.com/
>|||Hi There,
I hope this help to solve the problem.
Select identity(int,1,1) Seq into Seq From sysobjects
Select * from seq
Select Substring(String,1,Max(seq)) From
(
Select * From Seq ,(
Select 'c:\aa\bb\cc\dd\ee' As String) S
Where substring(String,seq,1) = '\'
) SS Group By String
Drop Table Seq
With Warm regards
Jatinder Singh