批处理分解数据库连接字符串

来自http://tunps.com/batch-scripting-resolve-db-conn-str

@echo off
rem tunpishuang[http://tunps.com]
rem 连接字符串格式:
rem provider password security "user id" "initial catalog" "data source"
rem provider server   database  uid       pwd
rem 211条记录
setlocal enabledelayedexpansion
set num=1
for /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!+1
rem echo [%%h %%i] [%%j %%k] [%%l %%m] [%%n %%o] [%%p %%q] [%%r %%s] !num!
if "%%n"=="UID" echo www.xxx.com %%o %%q >>conn.txt
if "%%n"=="User ID" echo www.xxx.com %%o %%k >>conn.txt
rem if "%%j"=="Password" echo %%k
rem if "%%p"=="PWD" echo %%q
rem 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
————–
发到cndos上面的一个帖子,但是没有鸟我,自己搞定。

About tunpishuang

just 4 fun·····
This entry was posted in 未分类 and tagged . Bookmark the permalink.

发表评论

电子邮件地址不会被公开。 必填项已用 * 标注

*

您可以使用这些 HTML 标签和属性: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>