4/25/2007 4:17 AM | |
Posts: 19 Rating:
|
But I have to make this connection by Visual Basic because with this I can embed it into Excel application. In addition, I am used to make script in Visual Basic with ADO tool for the connection rather than C. somebody has experience in this subject please help me! |
4/25/2007 8:43 AM | |
Posts: 1084 Rating:
|
Hi, Sorry I completly over looked that visual basic part. So in general you want to connect to a wincc database from with excel (through ado with VB)? with regards, Ikkezelf |
4/25/2007 10:42 AM | |
Posts: 19 Rating:
|
Yes, I want to connect to Sybase from Excel by ADO tool. If you have ever done somthing similar to what I am donging (my picture I attached is the system I want to make), give me some advice, thanks! |
4/25/2007 11:34 AM | |
Posts: 1084 Rating:
|
Hi, Got the following with help from Reuben: [code] Dim ado_con Dim ado_rs Dim dsn Dim count 'Extract DSN from static text object dsn = ScreenItems("txDSN").Text 'Create ADO database connection object Set ado_con = CreateObject("ADODB.Connection") ado_con.ConnectionString = "DSN=" & dsn 'Display message in diagnostic window HMIRuntime.Trace "Connect to: " & dsn & Chr(13) & Chr(10) HMIRuntime.Trace "All Tags in database:" & Chr(13) & Chr(10) & Chr(13) & Chr(10) 'Connect to database ado_con.Open 'Create ADO recordset object Set ado_rs = CreateObject("ADODB.Recordset") ado_rs.Open "SELECT * FROM MCPTVARIABLEDESC", ado_con, 1 count = 0 Do While Not ado_rs.EOF count = count + 1 HMIRuntime.Trace "- " & ado_rs.Fields(5).Value & Chr(13) & Chr(10) ado_rs.MoveNext Loop HMIRuntime.Trace Chr(13) & Chr(10) & "Total Tag Count: " & count 'Close database and free objects ado_rs.Close ado_con.Close Set ado_rs = Nothing Set ado_con = Nothing [/code] Is this what you need? The DSN name could be retrieved out of the wincc system tag (as of wincc V6.x) With regards, Ikkezelf |
4/26/2007 3:37 AM | |
Posts: 19 Rating:
|
thanks Mr. lkkezelf for your help. But I am using Simatic WinCC V5 (not WinCC V6.x). I have read your code but I don't understand what provides the dsn variable with value. And I think that you misunderstood my intention. I want to access Sybase from Visual Basic, not from WinCC. It means that I design a VB project independentof WinCCprojectand implement database access process from here but I have not been successful yet. |
4/26/2007 9:25 AM | |
Posts: 1084 Rating:
|
Sorry (again). In C-script you can retrieve the dns name by means of ODK calls. in visual basic I use wincc v6.0 and can retrieve it out of the internal tag. Wondering if there is another way to get it and then in vb. I once saw a script that read out all dsn's configured on the system. wincc dsn have some unique characters in which you can distinguish them. That could be a way. But you have to google for the script. Just search for "dns listing through vb" or something similair. You tell me that the dsn name is correct bit still he can't find the database (at least that's the result you're getting). Looks to me that tor the connectionstring is incorrect or there is no trusted connection between the two pc's. Have a look at this website for connectionstrings, or on this website for sybase onlinebooks Hope you find what you need. with regards, Ikkezelf |
4/26/2007 10:14 AM | |
Posts: 19 Rating:
|
Thank you very much for your help! I found the way to solve this problem. |
4/26/2007 10:19 AM | |
Posts: 1084 Rating:
|
Could you please post the solution heer, so others can benefit from it aswell? Thanks in advance. |
Follow us on