来自http://tunps.com/batch-scripting-resolve-db-conn-str
@echo offrem tunpishuang[http://tunps.com]rem 连接字符串格式:rem provider password security "user id" "initial catalog" "data source"rem provider server database uid pwdrem 211条记录setlocal enabledelayedexpansionset num=1for /f "usebackq" %%a in (`dir C:\Users\Administrator\Desktop\ConnectString4Web /s /b /a-d`) DO (for /f "delims=; tokens=1,2,3,4,5,6" %%b in (%%a) DO (for /f "delims== tokens=1,2,3,4,5,6,7,8,9,10,11,12" %%h in ("%%b=%%c=%%d=%%e=%%f=%%g") DO (set /a num=!num!+1rem echo [%%h %%i] [%%j %%k] [%%l %%m] [%%n %%o] [%%p %%q] [%%r %%s] !num!if "%%n"=="UID" echo www.xxx.com %%o %%q >>conn.txtif "%%n"=="User ID" echo www.xxx.com %%o %%k >>conn.txtrem if "%%j"=="Password" echo %%krem if "%%p"=="PWD" echo %%qrem echo !num!)))endlocal |
解释一下:
C:\Users\Administrator\Desktop\ConnectString4Web目录下面有很多数据库连接字符串的文件,内容有两种:
一种是:Provider=SQLOLEDB;Server=localhost;Database=xx;UID=xxxx;PWD=xxxxxx
还有一种是:Provider=SQLOLEDB.1;Password=xx;Persist Security Info=True;User ID=xx;Initial Catalog=xx;Data Source=(local)
如果通过批处理,将所需要的Server(Data source)、UID(user id)、PWD(password)提取到一个文件,格式为:
server1 uid1 pwd1
server2 uid2 pwd2
server3 uid3 pwd3
server2 uid2 pwd2
server3 uid3 pwd3
————–
发到cndos上面的一个帖子,但是没有鸟我,自己搞定。