can not retrieve data from sql server - sql

I can not retrieve data from db in sql server.
I use the c3p0 as the pool,this is the c3p0.properties:
c3p0.user=test
c3p0.password=123456
c3p0.jdbcUrl=jdbc:sqlserver://xxxxxx:1433;databaseName=TIMDB;SelectMethod=cursor
c3p0.driverClass=com.microsoft.sqlserver.jdbc.SQLServerDriver
c3p0.maxPoolSize=15
c3p0.testConnectionOnCheckin=true
c3p0.idleConnectionTestPeriod=3600
In the sql server,I have create a new user named test,and its default db is TIMDB,the server roles is public,and this is the user mapping:
But when I start the application,I can get nothing.
From the log created by log4j,I can get the sql used to retrieve data,but if I copy the sql to the sql management stutio and create a new query,I can retrieve some data.
I wonder why?

It looks like a permissions problem to me. If the generated SQl runs when you use it in management studio (i.e under your user account) then you know the code is good. What access have you given the user "test" from your post I see "user mapping: enter image description here"? he will need at least db_datareader and possibly more depending on what code is generated.
You could also try logging on to SQL Management studio under your "test" user and see if you can execute the code. That will eliminate the possibility that its something wrong with your application/network.

Related

CREATE USER in MS Access 2010

I have been searching for several hours regarding how to create a user using SQL for a database I am building in Access. I found several sources on Microsoft's website that say I can use the CREATE USER command to do this. However, whenever I attempt to run the query, an error saying Syntax error in CREATE TABLE statement pops up. What am I doing wrong? Thank you in advance for your help! If you're interested, the code format I am attempting to use is as follows: CREATE USER username, password, pid.
Access does support CREATE USER as a DDL statement, but unfortunately it won't work in all contexts. Specifically, it won't work if we try to run it from
the Query Designer within Access itself,
a DAO connection to the database, or
an ODBC connection to the database.
It will only work when run from an OLEDB connection to the database. That can be accomplished from VBA code within the Access database itself by using the CurrentProject.Connection object, like so:
CurrentProject.Connection.Execute _
"CREATE USER newuser newpassword newpid"
(Note that there are no commas between the three arguments to the CREATE USER statement.)

Sql: export database using TSQL

I have database connection to database DB1. The only thing I could do - execute any t-sql statements including using stored procedures. I want to export the specific table (or even the specific rows of specific table) to my local database. As you can read abve, DBs are on diffrent servers meaning no direct connection is possible. Therefore question: Is it possible to write query that returns the other query to execute on local server and get data? Also note, that table contains BLOBs. Thanks.
If you have SQL Server Management Studio, you can use the data import function on your local database to get the data. It works as long as you have Read/Select access on the tables you are trying to copy.
If you have Visual Studio you can use the database tools in there to move data between two servers as long as you can connect to both from your workstation.
Needs Ultimate or Premium though:
http://msdn.microsoft.com/en-us/library/dd193261.aspx
RedGate has some usefull tools too:
http://www.red-gate.com/products/sql-development/sql-compare/features
Maybe you should ask at https://dba.stackexchange.com/ instead.
If you can login to the remote db (where you can only issue t-sql), you may create linked server on your local server to the remote and use it later directly in queries, like:
select * from [LinkedServerName].[DatabaseName].[SchemaName].[TableName]

sql table view problem

I am new to SQL and I am facing problems. When I create any table, I can't view it. Also, is it possible to enter the data into the table via management studio?
Like Harry 1234 xyz?
If you entered the query right, and it shows that the commands have been successfully executed, you should be able to see the created table with no entries by using select * from table_name.
If you still cannot see the data, try refreshing the database. Now you should be able to see your data.
Many database engines support entering data directly without SQL statements (like Harry 1234 xyz) like Microsoft SQL Server, MySql, etc. How you do it will depend on which database engine you're using.
You have to refresh "Object Explorer" in Management Studio.
It doesn't know that you created an object via SQL script

Adding tables to sql server result in Domain\user.name.tablename

Our app uses migratordotnet to modify the backing SQL Server 2005 database. This works great 99% of the time but we are running into an issue. We have a client that is using and Active Directory group for sql server login and when new tables are added it creates them as Domain\login.table_name. What permissions are needed to be given to the AD group to add the tables as dbo.table_name? This does not happen in with all of our clients with similar configurations so I must be missing something.
Make sure that the default schema for that login / group is set to dbo.
Can you set the default schema for a group? I was unable to do that using the management studio. I am trying a solution now that specifies the schema "dbo.table_name"

SQL Server 2005: Invalid object name exception

In VS2005, I am using a DLL which accesses a SQL Server. The DLL returns a SQLException
Invalid object name 'tableXYZ'
but tableXYZ is a table in the database.
Should it be looking for dbo.tableXYZ instead? Is this a permissions issue with the login being used?
This could be an issue with the owner of the tableand permissions.
for example the table owner may be dbo so the full table name will be dbo.TableXYZ The user you connect as, could be for example SQLUser may not have access to the dbo schema. So can only access tables such as SQLuser.TableXYZ
I'd check the permissions that you use to connect to the database.
Using dbo.tableXYZ makes it clearer what you want - the tableXYZ in the default dbo schema. There could be a tableXYZ in another schema, too - then SQL Server might not know which one you want.
And it could most definitely be a permissions issue. If you connect to that database in SQL SErver Mgmt Studio as that user - can you see that tableXYZ table??
UPDATE: does the DLL require a specific connection string, that you might not have copied into your calling app's app.config file?? DLL's in .NET can't really have their own mylibrary.dll.config - it will not be read by .NET by default.
you have to use the databasename in your connection-string - otherwise it would just connect und you have to use dbo.databasename.tableXYZ.
you can find the various connection-strings here
As a starting point, you could turn on an SQL Server Profiler trace, to see how the DLL is connecting to the database. e.g. you should be able to see what credentials are being used. You could also confirm to make sure the code is connecting to the right database etc.