Wednesday, July 25, 2012

VBScript to Send Emails with Gmail

Code begins here:

'Usage: cscript sendemail.vbs "" "" ""
'Ex. No attach: cscript sendemail.vbs example@gmail.com "test subject line" "test email body"
'Ex. W/ attach: cscript sendemail.vbs example@gmail.com "test subject line" "test email body" "c:\scripts\log.txt"

'***********
'****CONFIGURE THE FROM EMAIL ADDRESS AND PASSWORD

Const fromEmail = "email_sender@gmail.com"
Const password = "password"

'****END OF CONFIGURATION
'***********

Dim emailObj, emailConfig
Set emailObj = CreateObject("CDO.Message")
emailObj.From = fromEmail
emailObj.To = WScript.Arguments.Item(0)
emailObj.Subject = WScript.Arguments.Item(1)
emailObj.TextBody = WScript.Arguments.Item(2)

If WScript.Arguments.Count > 3 Then
emailObj.AddAttachment WScript.Arguments.Item(3)
End If

Set emailConfig = emailObj.Configuration
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserver") = "smtp.gmail.com"
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpserverport") = 465
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusing") = 2
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpauthenticate") = 1
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/smtpusessl") = true
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendusername") = fromEmail
emailConfig.Fields("http://schemas.microsoft.com/cdo/configuration/sendpassword") = password
emailConfig.Fields.Update

emailObj.Send
Set emailobj = nothing
Set emailConfig = nothing



You can see that the code starts with example usage of how you can call the VBScript file. Given the nature of executing VBScript files you may or may not have to include the “cscript” portion, but in general you are always better off having it there to ensure that it will run on your computer just fine. Here’s an example of what it looks like when being executed from the command prompt:
vbscript send email gmail.png
Note: The “sendemail.vbs” file was located at the root of the C Drive when I ran this.
Armed with this script you should be able to take it and throw it into batch files, or call it from anywhere that can execute things via the command line. One thing you may want to consider is creating an extra email account just for sending these emails. Not only will that keep your “sent mail” clean in your primary Gmail account, but it will also be a bit more secure since the password for the sender account is stored in plain text within the script.
Here is a nicely formatted version of the VBScript from above that you can download, and have all ready to go for you (after you fill in the two email/password inside the script file, of course):

script download : http://cybernetnews.com/wp-content/uploads/2010/08/sendemail.zip
source: http://cybernetnews.com/vbscript-send-emails-using-gmail/

Thursday, July 5, 2012

常用链接

arket Report (市场跟踪):
http://finance.yahoo.com/
http://www.nasdaq.com/asp/econodayframe.asp
http://www.google.com/finance?hl=en&tab=we
http://stockcharts.com/def/servlet/Favorites.CServlet?obj=msumm

Economic Calendar (一周重要经济指标)
http://www.cnbc.com/id/15839168
http://www.marketwatch.com/economy-politics/calendars/economic?

Free Charts (作图网站):
http://stockcharts.com/h-sc/ui?s=spx
http://bigcharts.marketwatch.com/
http://www.freestockcharts.com

Futures and World Market (期指和世界市场):
http://www.cnbc.com/id/17689937/site/14081545/
http://money.cnn.com/data/premarket/

US Dollar Index (美元指数):
http://quotes.ino.com/chart/?s=NYBOT_dx

Trading Ideas (交易思路):
http://www.benzinga.com/trading-ideas

Earning Report Calendar (ER日程):
http://www.earnings.com/highlight.asp?client=cb
http://biz.yahoo.com/research/earncal/today.html

Option Tools (Option工具):
http://www.cboe.com/LearnCenter/RCTools.aspx

Stock Screener (股票筛选):
http://finviz.com/screener.ashx
http://www.stockta.com/cgi-bin/screen.pl?action=Form&cobrand=
http://www.stockfetcher.com/ui2/index.php

FOMC Meeting Schedule (美联储日程):
http://www.federalreserve.gov/newsevents/press/monetary/2009060

FDA Calendar (FDA日程):
http://www.rttnews.com/CorpInfo/FDACalendar.aspx?Node=B8

US Market Holidays (美股节假日):
http://www.nyse.com/about/newsevents/1176373643795.html

Broker Comparison (交易券商比较):
http://www.stocktradingtogo.com/compareonlinebrokers.html

Wednesday, July 4, 2012

Replicatioin Configuration Problem Error -- SQL Server is unable to connect to server (Configure Distribution Wizard)


sp_helpserver
--SELECT @@ServerName

you will see error servename like,
--WIN08R2-666 WIN08R2-666--rpc,rpc out,use remote collation 0   NULL 0 0

sp_dropserver 'WIN08R2-666'
--to remove it and

sp_addserver 'WIN08R2-342', 'LOCAL'
--add the server name.

System.Data.SqlClient.SqlError -When Restoring a Database to SQL Server


restore a database backup to SQL Server 2008 and he got the following error


Msg 3176, Level 16, State 1, Line 1 File 'D:\SQL Server 2008 DBs\test01.mdf' is claimed by 'SCTA_ORG_SECOND'(3) and 'SCTA_ORGANIZATION'(1). The WITH MOVE clause can be used to relocate one or more files.
Msg 3013, Level 16, State 1, Line 1
RESTORE DATABASE is terminating abnormally

let's resolve this error then we will explain the reason of this error so at the same screen used for restoring database of Microsoft SQL Server Management Studio 




select Script Action to New Query Window as the above image so you will get the following T-SQL and here we will know the reason


RESTORE DATABASE [test01] FROM  DISK = N'D:\SCTA_Org2.bak' WITH  FILE = 1,
    MOVE N'SCTA_ORGANIZATION' TO N'D:\SQL Server 2008 DBs\test01.mdf',
    MOVE N'SCTA_ORG_SECOND' TO N'D:\SQL Server 2008 DBs\test01.MDF',
    MOVE N'SCTA_ORGANIZATION_log' TO N'D:\SQL Server 2008 DBs\test01_1.ldf',
    NOUNLOAD,  STATS = 10
GO

so you will notice there are two files of mdf with the same name so just change the name of second one to test02 or to test01.ndf ( different extension) then run the command and it's successfully restored.

so the logical answer for this error first test01.mdf is a primary data file and the second is the secondary data file but the extension and name are same so that way you have to change the name or extension of second file with any other name or extension.

Note: the extension is anything ( it can be .fad or .ndf but .ndf is best practice to determine what this file for for example .ldf for log file , .ndf  for secondary data files ..).

Finally : I think the original database backup come from SQL Server 2000 and maybe this behavior allowed in SQL Server 2000 or the name is a case sensitive ( test01.mdf not like test01.MDF).


source: http://sqlgoogler.blogspot.ca/2011/01/systemdatasqlclientsqlerror-when.html

Saturday, June 30, 2012

VMware Esxi 5 如何添加/激活注册码


connect via vShpere Client->xxx (the VM ip)-->Configuration(tab)
-->Software-->Licensed Features-->Edit(right top)-->
Assign a new license key to this host -->Enter Key....

费我好几分钟去找。不知道是不是Vmware故意迷惑你让你以为Esxi要花钱

VMware Esxi 5 adding a virtual machine to the inventory 导入旧的VM


You can register a virtual machine in vCenter Server / VirtualCenter or from a command line.
 
To register a virtual machine in vCenter Server:
  1. Open the vSphere / VMware Infrastructure (VI) Client and log in with appropriate credentials.
  2. If connecting to vCenter Server, click on the desired host.
  3. Click the Configuration tab.
  4. Click Storage.
  5. Right-click on the appropriate datastore and click Browse Datastore.
  6. Navigate to the folder named after the virtual machine, and locate the .vmx file. 
  7. Right-click the .vmx file and click Add to inventory. The Add to Inventory wizard opens. 
  8. Continue to follow the wizard to add the virtual machine.
To register a virtual machine from a command line:
  1. Log in as root to the ESX host with an SSH client.
  2. Run the command:
    # vmware-cmd -s register \.vmx
To register a virtual machine from a command line on an ESXi host:
  1. Log in as root to the ESXi host with an SSH client. For information on using Tech Support mode, see Using Tech Support Mode in ESXi 4.1 (1017910).
  2. Run the command:

    # vim-cmd solo/registervm /vmfs/volumes/datastore_name/VM_directory/VM_name.vmx

Friday, June 29, 2012

start IDENTITY values at a new seed

This can be useful if you want to create an artificial gap between your current seed and your desired next identity value.

SET IDENTITY_INSERT [myTable] OFF
INSERT INTO [myTable] (id,other)
    VALUES(@NewSeed,'something')
SET IDENTITY_INSERT ON [myTable] ON 

In this case, the id column will continue incrementing from the vaue of @NewSeed.

If you want to remove all entries in a table and start over at 1 (or a non-default seed), you can do one of two things:

DROP TABLE [myTable]
CREATE TABLE [myTable]
(
    -- Column definition
)

-- or

TRUNCATE TABLE [myTable]

Note that TRUNCATE TABLE will not work in particular scenarios, e.g. if another table has a foreign key constraint pointing at the table you're trying to reset (even if there is no data representing that relationship). What you can do instead is:

DELETE [myTable] -- assuming you want to clear the data
DBCC CHECKIDENT('myTable', RESEED, 0)

The final parameter is a little awkward. If you want to make sure that the next IDENTITY value that gets generated is 1, you set this value to 0 (this is the typical case). If you want to inject a gap into the IDENTITY sequence, let's say you want the next IDENTITY to be 25000, you would say:

DBCC CHECKIDENT('myTable', RESEED, 24999)

Of course, that all assumes that your increment value is 1. If your increment value is 50, you would use 24950 instead of 24999.

It's not a great idea to reseed an IDENTITY sequence *lower* than any values that currently exist in the table. You might get a little surprise when your counter gets back up that high and hits an existing value...



For Access, you can reset the AUTONUMBER column by compacting and repairing the database (see Article #2190). Though with certain version / JET combinations, this can cause the engine to fill gaps when you start inserting again. KB #257408 explains this to some degree, but states that it will only use numbers lower than the max that was ever in the table, if all higher numbers have been deleted (e.g. won't fill gaps). There are several documented cases out on Google where users have observed their gaps being filled in, even when higher numbers still exist in the data. So I wouldn't count on your gaps staying intact.

source: http://sqlserver2000.databases.aspfaq.com/can-i-start-identity-values-at-a-new-seed.html