2015/3/10
這幾天遇到一點問題,無法訪問ms sql server .
需要注意幾個問題.
1.ms sql 的配置
安裝了 sql- server2005 express ,安裝默認會關閉網絡連接的等.需要打開ip:1433端口.
賬戶密碼需要使用,ms sql–server 登錄登錄.
2.sqlapi 的使用.
4.0.3 版本缺省使用odbc
Starting from version 4.0.3 SQLAPI++ Library uses ODBC as default API when working with SQL Server. If for some reason you want to use OLE DB or DB-Library, you should set "UseAPI" connection option before specifying SQL Server client or connecting to database:
SAConnection con;
con.setOption( "UseAPI" ) = "DB-Library";
con.setClient( SA_SQLServer_Client );
con.Connect(...);
3. 解決 18456 問題解析.
第一部分 數據庫配置
sql-server 2005 安裝.
sql-server 2005 management stduio express .微軟這些都是免費的.
連接串:
AP-CHN-LP140098\SQL2005EXPRESS
.\SQL2005EXPRESS
127.0.0.1\SQL2005EXPRESS
錯誤代碼:
28000 [Microsoft][SQL Server Native Client 10.0][SQL Server]?? ' ' ?????
實際原因是
sqlapi 4.0.1
1 SAConnection con;
2 con.setOption( "UseAPI" ) = "ODBC";
3 SACommand cmd(&con,"select 1 ");
4 try
5 {
6 con.Connect(dbname,name,pwd,SA_SQLServer_Client);
7 cmd.Execute();
注釋掉 con.setOption( "UseAPI" ) = "ODBC"; 就解決了。
錯誤的格式串:
42000 ????????????? "tcp:127.0.0.1\SQL2005EXPRESS,1433"??????
28000 ?? 'vip' ?????
42000 ????????????? "127.0.0.1\SQL2005EXPRESS"??????
28000 ?? 'vip' ?????
正確的sqlapi ++ ms sql server 串
char * dbname = "127.0.0.1\\SQL2005EXPRESS@master";
請參考 :
http://www.sqlapi.com/ServerSpecific/SQLServer_OleDb.html#Connecting%20to%20a%20database




如果這里下面這個服務無法顯示, 可能是 sql2013localdb 造成的卸載掉就ok了.

啟動然后端口都開成1433 ,64bit 和32bit都是用這個設置 allip



第二部分 sqlapi 代碼
我在sqlapi中連接串:
127.0.0.1\SQL2005EXPRESS@DaZong
注意是如果是string 里面的 \\ 代表 \
第三部分 登錄失敗跟蹤
1.請設置登錄失敗到日志. ms sql server logon 18456 error

C:\Program Files (x86)\Microsoft SQL Server\MSSQL.1\MSSQL\LOG

注意這里是 狀態 8 :
清查表:
ERROR STATE | ERROR DESCRIPTION |
2 and 5 | Invalid userid |
6 | Attempt to use a Windows login name with SQL Authentication |
7 | Login disabled and password mismatch |
8 | Password mismatch |
9 | Invalid password |
11 and 12 | Valid login but server access failure |
13 | SQL Server service paused |
18 | Change password required |
參考 :
http://blogs.msdn.com/b/sql_protocols/archive/2006/02/21/536201.aspx