|
Hi all,
Hope someone can help. I am maintaining a web service and having downloaded from VSS and compiled the service when I run it it fails. I have located the problem but cannot explain it or resolve it.
The code is attempting to read database connection information from the web.config file but what is being returned from the code
System.Configuration.ConfigurationSettings.AppSettings("server")
System.Configuration.ConfigurationSettings.AppSettings("catalog") etc.
is "nothing", literally! Does anyone have any idea why this might be happening? Any help would be greatly appreciated.
Thanks in advance, J
|
|
|
|
|
Is the config file in the same folder as the page that is trying to read it?? Are you sure you don't have more than one copy of the web.config file in the app? If you get "nothing" from these statements, it's because there either is no web.config file where it is supposed to be, is named improperly, or the XML document in the file is not written correctly.
|
|
|
|
|
Hi Dave,
Thanks for the reply. All yours points makes sense but none of them seem to be the reason behind my particular problem. This is a web service as well so it's not a page accessing the web.config file. The config file itself is in the correct folder and having reviewed the XML in the config file it appears to be correct.
Any other suggestions, at this stage, would be very welcome.
Thanks again, J
modified on Friday, July 10, 2009 5:15 AM
|
|
|
|
|
Hi all,
anyone knows how can I store a file into a blob field in Oracle? I'm using VB 2008 and adodb (v. 2.8) and oracle ver.9.2.0.1.0 I tried with some example downloaded from internet, but no one works fine. Any suggestion will be really appreciate.
Below you can see an example found in internet:
Public sub ImportFile(ByVal sFile as string)
Dim rs = New ADODB.Recordset
Dim st = New ADODB.Stream
rs.Open("Select * from doc_allegati where matricola = " & gMatricola, oConn, ADODB.CursorTypeEnum.adOpenKeyset, ADODB.LockTypeEnum.adLockOptimistic)
st.Type = ADODB.StreamTypeEnum.adTypeBinary
st.Open()
st.LoadFromFile(sFile)
With rs
.AddNew()
.Fields("ID").Value = 1
.Fields("Documento").Value = st.Read
.Update()
End With
rs.close
st.close
end sub
This not work; when I try to open the recordset vb give me back an error message such as: 'data type not supported'
Thaks in advance for your help,
Filippo
|
|
|
|
|
Lucky me - I don't use Oracle at all.
But, a quick Google reveals a bunch of possiblities. Results...[^]
|
|
|
|
|
Hi Dave,
you are right, but into the example I need to use ODP.NET. Is it possible to manage this kind of field without install this?
Thanks,
Filippo
|
|
|
|
|
So, you looked at one example that used ODP.NET. There are others in that list that use other database providers that work with Oracle.
Filippo1974 wrote: Is it possible to manage this kind of field without install this?
Keep reading through the results list and find out. This is what is called "research", and it's an integral part of any programming job.
|
|
|
|
|
Hi,
We have 'Primary Interop Assemblies' folder at the following path:
"C:\Program Files\Microsoft.NET\Primary Interop Assemblies"
How can we install them? or with which product we get these assemblies installed? any help would be greatly appreciated
Thank you,
Raheem MA
|
|
|
|
|
Primary Interop Assemblies would be supplied by the application that you want to interact with, such as Office 2003 or 2007. You can also download the PIA's seperately from Microsoft and run their installer.
|
|
|
|
|
Here is the IDL definition
[
object,
uuid(DAFB7D76-0158-452F-8FD0-FF97A683DEA3),
helpstring("ITest Interface"),
pointer_default(unique)
]
interface ITest : IUnknown
{
[helpstring("method GetString")] HRESULT GetString([out,retval] BSTR* pVal);
};
[
uuid(E768DC15-A19B-407C-ACF9-C420D6FDB1BE),
version(1.0),
helpstring("TestServer 1.0 Type Library")
]
library TESTSERVERLib
{
importlib("stdole32.tlb");
importlib("stdole2.tlb");
[
uuid(788571BD-030B-49CC-8C0A-2DF74E58331A),
helpstring("Test Class")
]
coclass Test
{
[default] interface ITest;
};
};
The ATL COM Library uses APARTMENT threading model.
And the VB.NET windows service code fragment
try
Dim obj As New TESTSERVERLib.Test
Dim s As String
s = obj.GetString()
Catch ex As Exception
WriteToLog(ex.Message)
WriteToLog(ex.InnerException.ToString)
End Try
When the code executes the following error occurs:
Unable to cast COM object of type 'TESTSERVERLib.TestClass' to interface type 'TESTSERVERLib.ITest'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{DAFB7D76-0158-452F-8FD0-FF97A683DEA3}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Object reference not set to an instance of an object.
But the same code works in VB.NET forms application.
Can anyone please explain the reason.
|
|
|
|
|
It appears that the problem comes down to the threading apartment model being used in your service app and your Windows Forms app. They appear to use different models.
You can check this by calling Thread.CurrentThread.AparmentState . It's either going to be STA ot MTA. Your COM component requires one threading model, and gets it under the Windows Forms app, but the service is using the other threading model.
|
|
|
|
|
The Apartment model in the VB.NET windows service is MTA. Whereas in the VB.NET forms application it is STA.
I experimented another method. I wrote a ATL component of type IDispatch interface. It works in both VB.NET forms application as well as VB.NET windows service.
The VB.NET windows service which I am going to write for my customer is a COM library using APARTMENT threading model. QueryInterface fails for all interfaces of type IUnknown. Can you elaborately explain the hidden details of why QueryInterface of type IUnknown fails in a VB .NET windows service and help me to make it work!
Thanks in Advance.
|
|
|
|
|
I have no idea. The internal working of COM are not my strong suit.
|
|
|
|
|
how can i connect crystal report to sql server with vb.net code ? i don know how to make connection for it. can u give me some example of making crystal report connection?
|
|
|
|
|
|
 If you just want to update your connection settings (dbname / loginid / loginpass) this code will do:
Private Function reconnectreport(ByVal report As ReportDocument, ByVal servernaam As String, ByVal dbnaam As String, ByVal dbLogin As String, ByVal dbPass As String) As ReportDocument
Try
Dim connection As IConnectionInfo
Dim oldServerName As String = report.DataSourceConnections(0).ServerName
Dim newServerName As String = servernaam
Dim oldDatabaseName As String = report.DataSourceConnections(0).DatabaseName
Dim newDatabaseName As String = dbnaam
Dim userID As String = dbLogin
Dim password As String = dbPass
report = report
' Change the server name and database in main reports
For Each connection In report.DataSourceConnections
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
' SetConnection can also be used to set new logon and new database table
report.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
End If
Next
' Change the server name and database in subreports
Dim subreport As ReportDocument
For Each subreport In report.Subreports
For Each connection In subreport.DataSourceConnections
If (String.Compare(connection.ServerName, oldServerName, True) = 0 _
And String.Compare(connection.DatabaseName, oldDatabaseName, True) = 0) Then
' SetConnection can also be used to set new logon and new database table
subreport.DataSourceConnections(oldServerName, oldDatabaseName).SetConnection( _
newServerName, newDatabaseName, userID, password)
End If
Next
Next
Return report
Catch ex As Exception
MessageBox.Show(ex.Message)
Return Nothing
End Try
End Function
|
|
|
|
|
please help in this regard. give the visual basic code for this as soon possible.
calculate difference between 2 dates and 2 times and display in years, months ,days,hours minutes in vb 6
for eg: if start date is 01/01/2008 and statr time is 10.45 am
end date is 02/02/2009 and end time is 11.45 am
it should display as 1 year 1 month 1 day 1 hour 0 minuts
|
|
|
|
|
Nobody is going to do your homework!
I can tell you that you need to use DateDiff function.
Good luck
Shay Noy
|
|
|
|
|
If your course is in VB6, you should abandon it, it's a fair sign that your teachers are clueless morons.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
It keeps amazing me that there still are schools teaching this.
Couple days ago I answered very similar to you 
|
|
|
|
|
Yeah, given that VB6 is obsolete, and VB.NET is free, I can only assume these guys are like the guys who used to teach C++, when they only really knew C.
Christian Graus
Driven to the arms of OSX by Vista.
Read my blog to find out how I've worked around bugs in Microsoft tools and frameworks.
|
|
|
|
|
I got the codes to send sms using VB and i came across these two sample codes.
Sending SMS using .NET[^]
http://www.daniweb.com/forums/post250164-19.html#[^]
I copied and paste the following codes in my Class Library file. i have bold the codes with problems.
Option Explicit On
Imports System
Imports System.Threading
Imports System.ComponentModel
Imports System.Windows.Forms
Imports System.IO.Ports
Public Class SMSCOMMS
Private WithEvents SMSPort As SerialPort
Private SMSThread As Thread
Private ReadThread As Thread
Shared _Continue As Boolean = False
Shared _ContSMS As Boolean = False
Private _Wait As Boolean = False
Shared _ReadPort As Boolean = False
Private WithEvents DBServer As Postgres " PROBLEM - type 'Postgres' is not defined "
Public Event Sending(ByVal Done As Boolean)
Public Event DataReceived(ByVal Message As String)
Public Sub New(ByRef COMMPORT As String)
SMSPort = New SerialPort
With SMSPort
.PortName = COMMPORT
.BaudRate = 9600
.Parity = Parity.None
.DataBits = 8
.StopBits = StopBits.One
.Handshake = Handshake.RequestToSend
.DtrEnable = True
.RtsEnable = True
.NewLine = vbCrLf
End With
DBServer = New Postgres() " PROBLEM - type 'Postgres' is not defined "
ReadThread = New Thread(AddressOf ReadPort)
End Sub
Public Function SendSMS(ByVal CellNumber As String, ByVal SMSMessage As String) As Boolean
Dim MyMessage As String = Nothing
'
'Check if Message Length <= 160
If SMSMessage.Length <= 160 Then
MyMessage = SMSMessage
Else
MyMessage = Mid(SMSMessage, 1, 160)
End If
'MsgBox("Sending " & MyMessage & " to " & CellNumber)
If IsOpen = True Then
SMSPort.WriteLine("AT+CMGS=" & CellNumber & vbCr)
_ContSMS = False
While _ContSMS = False
Application.DoEvents()
End While
SMSPort.WriteLine(MyMessage & vbCrLf & Chr(26))
_Continue = False
RaiseEvent Sending(False)
End If
End Function
Private Sub ReadPort()
Dim SerialIn As String = Nothing
Dim RXBuffer(SMSPort.ReadBufferSize) As Byte
Dim SMSMessage As String = Nothing
Dim Strpos As Integer = 0
Dim TmpStr As String = Nothing
While SMSPort.IsOpen = True
If (SMSPort.BytesToRead <> 0) And (SMSPort.IsOpen = True) Then
While SMSPort.BytesToRead <> 0
SMSPort.Read(RXBuffer, 0, SMSPort.ReadBufferSize) 'SMSPort.BytesToRead
SerialIn = SerialIn & System.Text.Encoding.ASCII.GetString(RXBuffer)
' Handle Internal Events
' For Received Characters
If SerialIn.Contains(">") = True Then
_ContSMS = True
End If
If SerialIn.Contains("+CMGS:") = True Then
_Continue = True
RaiseEvent Sending(True)
_Wait = False
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
RaiseEvent DataReceived(SerialIn)
SerialIn = String.Empty
ReDim RXBuffer(SMSPort.ReadBufferSize)
End If
End While
End Sub
Public ReadOnly Property IsOpen() As Boolean
Get
If SMSPort.IsOpen = True Then
IsOpen = True
Else
IsOpen = False
End If
End Get
End Property
Public Sub Open()
If IsOpen = False Then
SMSPort.Open()
ReadThread.Start()
End If
End Sub
Public Sub Close()
If IsOpen = True Then
SMSPort.Close()
End If
End Sub
End Class
Next, i have also copied the following codes below into my windows form. I'm not sure if i've pasted the codes in the write place but that is wat i have done.
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
SMSEngine = New SMSCOMMS("COM1")
SMSEngine.Open()
SMSEngine.SendSMS("919888888888", "SMS Testing")
SMSEngine.Close()
End Sub
The problem i faced is that the SMSEngine was not declared. How do i solve this?
THANKS IN ADVANCE!!
|
|
|
|
|
If you took the time to try and understand the code instead of just Copy'N'Paste what you don't understand and expecting it to work, then you would realize that this code uses a Postgres database for something that probably has nothing to do with sending SMS messages. It looks like you can get rid of those two lines and not worry about them.
|
|
|
|
|
haha. Thanks for your help. I'm new to visual basics and started only a few days ago, so i dun really get what some of the codes are used for. Sorry. haha. I need to use these codes to do a project.
Am i doin things the right way? like where i placed the codes in my program? How do i define or declare the SMSEngine in the codes? thanks
|
|
|
|
|
gjx_junxian1989 wrote: Am i doin things the right way?
Copy'N'Paste coding? Hell No.
gjx_junxian1989 wrote: where i placed the codes in my program?
I have no idea hwere you placed any of this stuff in your app.
gjx_junxian1989 wrote: How do i define or declare the SMSEngine in the codes?
What SMS Engine? Your code snippet doesn't mention anything about an engine. Or are you saying that the code you posted IS the engine? If so, then your problems do not lie in knowing VB.NET, but the basic concepts of object oriented programming. These are design issues that I really can't walk you through in a forum post.
|
|
|
|