This is a multi-part message in MIME format.

------=_NextPart_000_00A0_01C4A706.62151E10
Content-Type: text/plain;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

I am developing a custom application for Microstation v8. My app =
connects to an Access database (I haven't yet hooked it up to =
Microstation).

Within my code I have two very similar functions to query a database for =
a particular record. They are:

Public Function GetProjCfgFromDb(ByVal lProjID As Long) As String
Try
'connection stuff
Dim Conn As New OleDbConnection(sConnString & dbFullPath)
Dim strSQL As String =3D "SELECT proj_cfg FROM tbl_projects =
WHERE proj_id =3D " & lProjID
Dim Cmd As New OleDbCommand(strSQL, Conn)
Conn.Open()

GetProjCfgFromDb =3D CType(Cmd.ExecuteScalar(), String)

'cleanup
Conn.Dispose()
Conn =3D Nothing
Cmd.Dispose()
Cmd =3D Nothing

Catch ex As Exception
MsgBox(ex.Source & ex.Message, MsgBoxStyle.Critical)
End Try
End Function

Public Function GetProjIDFromDb(ByVal sProjCfg As String) As Long
Try
'connection stuff
Dim Conn As New OleDbConnection(sConnString & dbFullPath)
Dim strSQL As String =3D "SELECT proj_id FROM tbl_projects =
WHERE proj_cfg =3D " & sProjCfg
Dim Cmd As New OleDbCommand(strSQL, Conn)
Conn.Open()

GetProjIDFromDb =3D CType(Cmd.ExecuteScalar(), Long)

'cleanup
Conn.Dispose()
Conn =3D Nothing
Cmd.Dispose()
Cmd =3D Nothing

Catch ex As Exception
MsgBox(ex.Source & ex.Message, MsgBoxStyle.Critical)
End Try
End Function
=20
=20

This first function is called like this:

Dim sProjConfig As String
sProjConfig =3D GetProjCfgFromDb(CLng(Me.cboProjects.SelectedValue))


and works perfectly, but the second function is called like this:

Private Sub CheckForProject()
If IsProcessExecuting("ustation") =3D False Then
projectForm =3D New frmProj
projectForm.ShowDialog()
Else
'process is executing so get the project
'configuration file currently selected
'and set project ID from database
oMSTN =3D New MicrostationDGN.Application

Dim sConfigName As String
sConfigName =3D =
oMSTN.ActiveWorkspace.ConfigurationVariableValue("_USTN_PROJECTNAME")

lProj_ID =3D GetProjIDFromDb(sConfigName)
End If
End Sub


where =
oMSTN.ActiveWorkspace.ConfigurationVariableValue("_USTN_PROJECTNAME") =
returns a string (eg "SRA 1957 BGS Lower School"). =20


GetProjIDFromDb() fails ion this line:

GetProjIDFromDb =3D CType(Cmd.ExecuteScalar(), Long)


I have checked all the obvious things but I cannot see what is causing =
the error.

Please help

Russ


------=_NextPart_000_00A0_01C4A706.62151E10
Content-Type: text/html;
charset="iso-8859-1"
Content-Transfer-Encoding: quoted-printable

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; =
charset=3Diso-8859-1">
<META content=3D"MSHTML 6.00.2800.1400" name=3DGENERATOR>
<STYLE></STYLE>
</HEAD>
<BODY bgColor=3D#ffffff>
<DIV><FONT face=3DArial size=3D2>I am developing a custom application =
for=20
Microstation v8. My app connects to an Access database (I haven't yet =
hooked it=20
up to Microstation).</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Within my code I have two very similar =
functions to=20
query a database for a particular record. They are:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Public Function=20
GetProjCfgFromDb(ByVal lProjID As Long) As=20
String<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
Try<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
=20
'connection=20
stuff<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; Dim=20
Conn As New OleDbConnection(sConnString &amp;=20
dbFullPath)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
Dim strSQL As String =3D "SELECT proj_cfg FROM tbl_projects WHERE =
proj_id =3D "=20
&amp;=20
lProjID<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
Dim Cmd As New OleDbCommand(strSQL,=20
Conn)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
Conn.Open()</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
GetProjCfgFromDb =3D CType(Cmd.ExecuteScalar(), String)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
'cleanup<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;=20
Conn.Dispose()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;=20
Conn =3D=20
Nothing<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
Cmd.Dispose()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
Cmd =3D Nothing</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch ex=20
As=20
Exception<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;=20
MsgBox(ex.Source &amp; ex.Message,=20
MsgBoxStyle.Critical)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End=20
Try<BR>&nbsp;&nbsp;&nbsp; End Function</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>&nbsp;&nbsp;&nbsp; Public Function=20
GetProjIDFromDb(ByVal sProjCfg As String) As=20
Long<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=20
Try<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
=20
'connection=20
stuff<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p; Dim=20
Conn As New OleDbConnection(sConnString &amp;=20
dbFullPath)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;&nbsp;=20
Dim strSQL As String =3D "SELECT proj_id FROM tbl_projects WHERE =
proj_cfg =3D "=20
&amp;=20
sProjCfg<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;=20
Dim Cmd As New OleDbCommand(strSQL,=20
Conn)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
Conn.Open()</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
GetProjIDFromDb =3D CType(Cmd.ExecuteScalar(), Long)</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial=20
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbs=
p;=20
'cleanup<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;=20
Conn.Dispose()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&=
nbsp;&nbsp;=20
Conn =3D=20
Nothing<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;=20
Cmd.Dispose()<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&n=
bsp;&nbsp;=20
Cmd =3D Nothing</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial =
size=3D2>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; Catch ex=20
As=20
Exception<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;=
&nbsp;=20
MsgBox(ex.Source &amp; ex.Message,=20
MsgBoxStyle.Critical)<BR>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; End=20
Try<BR>&nbsp;&nbsp;&nbsp; End=20
Function<BR>&nbsp;&nbsp;&nbsp;&nbsp;<BR>&nbsp;&nbsp;&nbsp; </FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>This first function is called like=20
this:</FONT></DIV>
<DIV>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2>Dim sProjConfig As =
String<BR>sProjConfig =3D=20
GetProjCfgFromDb(CLng(Me.cboProjects.SelectedValue))</FONT></DIV>
<DIV>&nbsp;</DIV><FONT face=3DArial size=3D2>
<DIV><BR>and works perfectly, but the second function is called like =
this:</DIV>
<DIV>&nbsp;</DIV>
<DIV>Private Sub CheckForProject()<BR>&nbsp;If =
IsProcessExecuting("ustation") =3D=20
False Then<BR>&nbsp;&nbsp;projectForm =3D New=20
frmProj<BR>&nbsp;&nbsp;projectForm.ShowDialog()<BR>&nbsp;Else<BR>&nbsp;&n=
bsp;'process=20
is executing so get the project<BR>&nbsp;&nbsp;'configuration file =
currently=20
selected<BR>&nbsp;&nbsp;'and set project ID from =
database<BR>&nbsp;&nbsp;oMSTN =3D=20
New MicrostationDGN.Application</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;Dim sConfigName As String<BR>&nbsp;&nbsp;sConfigName =
=3D=20
oMSTN.ActiveWorkspace.ConfigurationVariableValue("_USTN_PROJECTNAME")</DI=
V>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;&nbsp;lProj_ID =3D GetProjIDFromDb(sConfigName)<BR>&nbsp;End =
If<BR>End=20
Sub</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>where=20
oMSTN.ActiveWorkspace.ConfigurationVariableValue("_USTN_PROJECTNAME") =
returns a=20
string (eg "SRA 1957 BGS Lower School").&nbsp; </DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>GetProjIDFromDb() fails ion this line:</DIV>
<DIV>&nbsp;</DIV>
<DIV>GetProjIDFromDb =3D CType(Cmd.ExecuteScalar(), Long)</DIV>
<DIV>&nbsp;</DIV>
<DIV><BR>I have checked all the obvious things but I cannot see what is =
causing=20
the error.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Please help</DIV>
<DIV>&nbsp;</DIV>
<DIV>Russ</FONT></DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV>
<DIV><FONT face=3DArial size=3D2></FONT>&nbsp;</DIV></BODY></HTML>

------=_NextPart_000_00A0_01C4A706.62151E10--