public static void main(String[] args) {
// TODO Auto-generated method stub
String driverName = "com.microsoft.sqlserver.jdbc.SQLServerDriver"; // 加载JDBC驱动
String dbURL = "jdbc:sqlserver://localhost:1433;integratedSecurity=true;DatabaseName=Test"; // 连接服务器和数据库sample
String userName = "sa"; // 默认用户名
String userPwd = "luohai"; // 密码
Connection dbConn;
try {
Class.forName(driverName);
dbConn = DriverManager.getConnection(dbURL, userName, userPwd);
// dbConn = DriverManager.getConnection(dbURL);
System.out.println("Connection Successful!"); // 如果连接成功 jdbc.jar package is also added to the list , the user name password are right, there are connected database . Error com.microsoft.sqlserver.jdbc.SQLServerException: Can not open database requested by the login "Test". Login failed . ,
If the databaseName = test can be removed to connect to the default database without error Why ? ? ?
------ Solution ---------------------------------------- ----
look at there own database named Test , should not create the database.
------ Solution ---------------------------------------- ----
certainly not Test this database
------ Solution --------------------------- -----------------
first : Do you have a database called test
Second: Your sa whether to authorize the
------ For reference only ------------------------- --------------
your database name is not called that , is not it the table name and database name mixed up.
------ For reference only -------------------------------------- -
have a database and authorize sa the
------ For reference only --------------------------- ------------
questions added ah :
the database into the system database can be. Into their own database created on the error . Why ? ? ?
------ For reference only -------------------------------------- -
looked a bit wrong
------ For reference only ------------------------------ ---------
how wrong ah
------ For reference only ----------------------- ----------------
solved. Log sql2005 server name when there are two
are DADI-20121017JL \ SQLEXPRESS and DADI-20121017JL
java default when connecting to the database should be DADI-20121017JL
The DADI-20121017JL landing into the database without Test
test database built on DADI-20121017JL \ SQLEXPRESS in .
------ For reference only -------------------------------------- -
Will the landing . \ SQLEXPRESS that url should be how to write
------ For reference only -------------------- -------------------
too right, log in with java is localhost , ie 127.0.0.1, rather sql management registry is express , and learn !
------ For reference only -------------------------------------- -
I have encountered this problem ! Plagued by a long time could give more explanation about it ?
------ For reference only ---------------------------------- -----
again to change the logged in user to create, solve the problem, get a long , depressed.
------ For reference only -------------------------------------- -
me too, me too, thank you to share ! get yourself quite a while !
没有评论:
发表评论