File Sharing Violation

B

Butt Chin Chuan

I got this error where I'm given the error message below:

Index #0
Error:
System.Data.SqlServerCe.SqlCeError: This is a file sharing
violation. A different process might be using the file.
[,,,,,]

The following code is the culprit, although I don't know
how to overcome it. When I try to put a message box in the
code, the message box keeps looping itself. I wonder why?
I mean, I just bind a datatable to a combobox, it
shouldn't trigger any loop, right? I've solve this type of
error before, it usually comes out when i didn't open a
connection or haven't close a connection, but this
completely something else, since it keeps looping around.
In this code, I should get 6 items to be binded to
combobox, and the message box only appear once. However, I
keep having to press the Ok button on the message box so
many times until the application hang and give me the
error message above. Please comment. Any help is welcomed.
Thank you very much in advance.

Private Sub LoadServiceAttribute()
Dim objSqlDataAdapter as New SqlCeDataAdapter
Dim objDataSet as New DataSet
Dim objDataTable as New DataTable

sqlconn = New SqlCeConnection
'Create a connection string
sqlconn.ConnectionString = "DataSource=\My
Documents\mobileISSQ.sdf"
'Make another copy of the connection string
strConnection = sqlconn.ConnectionString
Dim objConnection As New SqlCeConnection
(strConnection)

Msgbox ("here")

sqlconn.Open()

sql = "SELECT distinct ServAttribList.nameBM as
ServiceAttribute " & _
"FROM ServAttribList, ServIntResp " & _
"where ServAttribList.sgid = '" & Gsgid
& "' " & _
"and ServAttribList.said =
ServIntResp.said"
'MsgBox(sql)
objSqlDataAdapter = New SqlCeDataAdapter(sql,
sqlconn)
objSqlDataAdapter.SelectCommand = New SqlCeCommand
(sql, sqlconn)
objSqlDataAdapter.Fill
(objDataSet, "ServAttributeList")
objDataTable = objDataSet.Tables
("ServAttributeList")
cbAttribute.DataSource = objDataSet.Tables
("ServAttributeList")
cbAttribute.DisplayMember = "Service Attribute"
cbAttribute.ValueMember = "ServiceAttribute"
lblAttributeDetail.Text = cbAttribute.Text
sqlconn.Close()

End Sub
 
A

Alex Feinman [MVP]

You are trying to open two connections to the same SQL CE database file.
This is not supported. It looks though that objConnection is not used
anywhere. Comment it out
 
B

Butt Chin Chuan

The objConnection is declared, but not used, so it
shouldn't cause any problems, right?

Also, one of the other causes that might cause this
problem is that in the ComboBox1.SelectedIndexChanged
procedure, I set it to load this procedure
(LoadServiceAttribute) whenever the index is changed.
However, I also set it to activate any changes only if the
LoadServiceAttribute is done for the first time. I set a
variable, Dim LoadAttribute as Boolean = False initially
and after loading LoadServiceAttribute, I will set
LoadAttribute = True and only then the
ComboBox1.SelectedIndexChanged procedure will be
activated. (Well, I think so, not too sure anymore, since
I still can't solve my problem). Any comment? Thank you.
-----Original Message-----
You are trying to open two connections to the same SQL CE database file.
This is not supported. It looks though that objConnection is not used
anywhere. Comment it out

I got this error where I'm given the error message below:

Index #0
Error:
System.Data.SqlServerCe.SqlCeError: This is a file sharing
violation. A different process might be using the file.
[,,,,,]

The following code is the culprit, although I don't know
how to overcome it. When I try to put a message box in the
code, the message box keeps looping itself. I wonder why?
I mean, I just bind a datatable to a combobox, it
shouldn't trigger any loop, right? I've solve this type of
error before, it usually comes out when i didn't open a
connection or haven't close a connection, but this
completely something else, since it keeps looping around.
In this code, I should get 6 items to be binded to
combobox, and the message box only appear once. However, I
keep having to press the Ok button on the message box so
many times until the application hang and give me the
error message above. Please comment. Any help is welcomed.
Thank you very much in advance.

Private Sub LoadServiceAttribute()
Dim objSqlDataAdapter as New SqlCeDataAdapter
Dim objDataSet as New DataSet
Dim objDataTable as New DataTable

sqlconn = New SqlCeConnection
'Create a connection string
sqlconn.ConnectionString = "DataSource=\My
Documents\mobileISSQ.sdf"
'Make another copy of the connection string
strConnection = sqlconn.ConnectionString
Dim objConnection As New SqlCeConnection
(strConnection)

Msgbox ("here")

sqlconn.Open()

sql = "SELECT distinct ServAttribList.nameBM as
ServiceAttribute " & _
"FROM ServAttribList, ServIntResp " & _
"where ServAttribList.sgid = '" & Gsgid
& "' " & _
"and ServAttribList.said =
ServIntResp.said"
'MsgBox(sql)
objSqlDataAdapter = New SqlCeDataAdapter(sql,
sqlconn)
objSqlDataAdapter.SelectCommand = New SqlCeCommand
(sql, sqlconn)
objSqlDataAdapter.Fill
(objDataSet, "ServAttributeList")
objDataTable = objDataSet.Tables
("ServAttributeList")
cbAttribute.DataSource = objDataSet.Tables
("ServAttributeList")
cbAttribute.DisplayMember = "Service Attribute"
cbAttribute.ValueMember = "ServiceAttribute"
lblAttributeDetail.Text = cbAttribute.Text
sqlconn.Close()

End Sub


.
 
C

Chin Chuan Butt

I didn't left my Query Analyzer open. Here is the other procedure that I
think might be the other cause of the problem, which occurs together
with the first procedure. Please comment. Thank you.

p/s: In case some of you might ask, I left the objConnection there
unused because I actually forgot to comment it out (leftover from
changing the connection from SQL2000 to SQLCE).

Private Sub cbAttribute_SelectedIndexChanged(ByVal sender As
System.Object, ByVal e As System.EventArgs) Handles
cbAttribute.SelectedIndexChanged
If loadStatus = 0 Then
Exit Sub
End If

If formInitialize = False Then
Exit Sub
End If

If formInitialize = True Then
Try
If GraphType = 1 Then

lblAttributeDetail.Text = cbAttribute.Text
graphicsObject.Clear(Color.White)
InitializeGraph()

objSqlDataAdapter1 = New SqlCeDataAdapter
objDataSet1 = New DataSet
objDataTable1 = New DataTable


sqlconn = New SqlCeConnection
'Create a connection string
sqlconn.ConnectionString = "DataSource=\My Documents\mobileISSQ.sdf"
'Make another copy of the connection string
strConnection = sqlconn.ConnectionString
Dim objConnection As New SqlCeConnection(strConnection)

sqlconn.Open() 'Open connection

sql = "select count(ServIntResp.sirid) " & _
"as TotalRespondent, " & _
"sum(ServIntResp.p) as Performance, " & _
"sum(ServIntResp.e) as Expectation " & _
"from ServIntResp, ServAttribList " & _
"where(ServIntResp.said = ServAttriblist.said) " & _
"and ServAttribList.nameBM = '" & _
cbAttribute.Text & "' "
'MsgBox(sql)
objSqlDataAdapter1 = New SqlCeDataAdapter(sql, sqlconn)
objSqlDataAdapter1.SelectCommand = New SqlCeCommand(sql, sqlconn)
objSqlDataAdapter1.Fill(objDataSet1, "ServCalc")
objDataTable1 = objDataSet1.Tables("ServCalc")
TotalRespondent = CInt(objDataTable1.Rows(0).Item("TotalRespondent"))
Performance = CInt(objDataTable1.Rows(0).Item("Performance"))
Expectation = CInt(objDataTable1.Rows(0).Item("Expectation"))
sqlconn.Close()
'MsgBox(TotalRespondent)
'MsgBox(Performance)
'MsgBox(Expectation)

plotX = CInt(Expectation / TotalRespondent)
plotY = CInt(Performance / TotalRespondent)
graphicsObject.DrawEllipse(blackPen, (plotX * 20) + 40, 180 - (plotY *
20), 5, 5)
graphicsObject.FillEllipse(redBrush, (plotX * 20) + 40, 180 - (plotY *
20), 5, 5)

pbGraph.Refresh()
End If

If GraphType = 4 Then

lblAttributeDetail.Text = cbAttribute.Text
graphicsObject.Clear(Color.White)
InitializeGraph()

objSqlDataAdapter1 = New SqlCeDataAdapter
objDataSet1 = New DataSet
objDataTable1 = New DataTable


sqlconn = New SqlCeConnection
'Create a connection string
'sqlconn.ConnectionString = "Data Source=SqServer; User ID = sa; " & _
' "Password=admin; Initial Catalog=ISSQ2003; "
sqlconn.ConnectionString = "DataSource=\My Documents\mobileISSQ.sdf"
'Make another copy of the connection string
strConnection = sqlconn.ConnectionString
Dim objConnection As New SqlCeConnection(strConnection)

sqlconn.Open() 'Open connection

sql = "select count(MgmtIntResp.mirid) " & _
"as TotalRespondent, " & _
"sum(MgmtIntResp.p) as Performance, " & _
"sum(MgmtIntResp.e) as Expectation " & _
"from MgmtIntResp, MgmtAttribList " & _
"where(MgmtIntResp.maid = MgmtAttriblist.maid) " & _
"and MgmtAttribList.nameBM = '" & _
cbAttribute.Text & "' "
'MsgBox(sql)
objSqlDataAdapter1 = New SqlCeDataAdapter(sql, sqlconn)
objSqlDataAdapter1.SelectCommand = New SqlCeCommand(sql, sqlconn)
objSqlDataAdapter1.Fill(objDataSet1, "MgmtCalc")
objDataTable1 = objDataSet1.Tables("MgmtCalc")
TotalRespondent = CInt(objDataTable1.Rows(0).Item("TotalRespondent"))
Performance = CInt(objDataTable1.Rows(0).Item("Performance"))
Expectation = CInt(objDataTable1.Rows(0).Item("Expectation"))
sqlconn.Close()
'MsgBox(TotalRespondent)
'MsgBox(Performance)
'MsgBox(Expectation)

plotX = CInt(Expectation / TotalRespondent)
plotY = CInt(Performance / TotalRespondent)
graphicsObject.DrawEllipse(blackPen, (plotX * 20) + 40, 180 - (plotY *
20), 5, 5)
graphicsObject.FillEllipse(redBrush, (plotX * 20) + 40, 180 - (plotY *
20), 5, 5)

pbGraph.Refresh()
End If
Catch ex As SqlCeException
DisplaySQLCEErrors(ex)
End Try
End If

Private Sub frmGraph_Activated(ByVal sender As Object, ByVal e As
System.EventArgs) Handles MyBase.Activated
If GraphType = 1 Then
InitializeGraph()
LoadServiceAttribute()
pbGraph.Image = GraphBackGround
loadStatus = 1
formInitialize = True
'cbAttribute.SelectedIndex = -1
'lblAttributeDetail.Text = ""
End If

If GraphType = 4 Then
InitializeGraph()
LoadManagementAttribute()
pbGraph.Image = GraphBackGround
loadStatus = 1
formInitialize = True
'cbAttribute.SelectedIndex = -1
'lblAttributeDetail.Text = ""
End If
End Sub

Butt Chin Chuan
A beginner in .Net Compact Framework development
 

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