Showing posts with label empty. Show all posts
Showing posts with label empty. Show all posts

Monday, March 19, 2012

connection is successful for empty userid

Hi,
In my application , the connection to SQLServer is established
through a DSN name, UserId and Password(both UsrId and Password are
non empty) . The "SQLConnect" function is used for this purpose. The
problem is that the connection to the Database is success when I give
an empty UserId. But this problem is not there when the UserId is
invalid(non empty).In all the cases except for empty UserId , the
connection works as expectd.
Why is it connecting for empty UserId?
Is it because that default windows authentication is used for
connection when UserId is empty?
If so is there any way to avoid this (through a C/C++ program)?
pls help
Thanks
KaimalIf the connection is success full and accessing the data base objects (table
,
view, stored procedure, etc) fails then this likely failing due to a
ownership chain problem. Recommend reading (SQL Server Books on Line) BOL
topics.
Using Ownership Chains
Logins
sp_grantdbaccess
sp_grantlogin or sp_addlogin
TSQL GRANT statement
I think what you are asking is to allow Public or Guest permission to your
database. Is this what you are after?
SQL Server's default behaviour is to lock all database objects. You have to
grant permission to the objects before they are accessible.
"Kaimal" wrote:

> Hi,
> In my application , the connection to SQLServer is established
> through a DSN name, UserId and Password(both UsrId and Password are
> non empty) . The "SQLConnect" function is used for this purpose. The
> problem is that the connection to the Database is success when I give
> an empty UserId. But this problem is not there when the UserId is
> invalid(non empty).In all the cases except for empty UserId , the
> connection works as expectd.
> Why is it connecting for empty UserId?
> Is it because that default windows authentication is used for
> connection when UserId is empty?
> If so is there any way to avoid this (through a C/C++ program)?
> pls help
> Thanks
> Kaimal
>|||> Is it because that default windows authentication is used for
> connection when UserId is empty?
>
Yes.

> If so is there any way to avoid this (through a C/C++ program)?
AFAIK, you'll need to check for the empty userid in your application code
and allow the connection only when not empty.
Hope this helps.
Dan Guzman
SQL Server MVP
"Kaimal" <rbkaimal@.hotmail.com> wrote in message
news:19aff12c.0504220154.142bf7e3@.posting.google.com...
> Hi,
> In my application , the connection to SQLServer is established
> through a DSN name, UserId and Password(both UsrId and Password are
> non empty) . The "SQLConnect" function is used for this purpose. The
> problem is that the connection to the Database is success when I give
> an empty UserId. But this problem is not there when the UserId is
> invalid(non empty).In all the cases except for empty UserId , the
> connection works as expectd.
> Why is it connecting for empty UserId?
> Is it because that default windows authentication is used for
> connection when UserId is empty?
> If so is there any way to avoid this (through a C/C++ program)?
> pls help
> Thanks
> Kaimal|||checking for empty UserId wil not help . I have to verify for the user
id depending on the authentication set in the ODBC driver. Here user is
free to set a blank id or other way round for a particular DSN.
The actal problem is that i have set a non empty UserId and Password for
a my DSN and the connection is established when i gave empty userid for
this DSN.
i would like to know about any ODBC function to this default connect.
can any thing be done with SQLSetConnectAttr function?
Thanks
Kaimal
*** Sent via Developersdex http://www.examnotes.net ***|||Allowing a "empty UserId and Password" is not a good Idea. You potentially
are opening up your SQL Server and database to security threats similar to
the Code Red virus. I think what you are after is an application base
security model. Check out the BOL sp_addapprole.
"Ragesh Kaimal" wrote:

> checking for empty UserId wil not help . I have to verify for the user
> id depending on the authentication set in the ODBC driver. Here user is
> free to set a blank id or other way round for a particular DSN.
> The actal problem is that i have set a non empty UserId and Password for
> a my DSN and the connection is established when i gave empty userid for
> this DSN.
> i would like to know about any ODBC function to this default connect.
> can any thing be done with SQLSetConnectAttr function?
> Thanks
> Kaimal
>
> *** Sent via Developersdex http://www.examnotes.net ***
>

Tuesday, February 14, 2012

Connecting to the SQL Database

Hi all,

I am new to this field. I am trying to Connect to the database using the following code. The code does not give an error but gives an empty grid view.

Can somebody figure out the mistake?

protectedvoid Page_Load(object sender,EventArgs e)

{

if (!IsPostBack)

BindGridView();

}

void BindGridView()

{

System.Data.SqlClient.SqlConnection sqlconnect =new System.Data.SqlClient.SqlConnection("");//added connection string here

String command ="SELECT * from table";

System.Data.SqlClient.SqlCommand sqlcommand =new System.Data.SqlClient.SqlCommand();

sqlcommand.CommandText = command;

sqlcommand.Connection = sqlconnect;

System.Data.SqlClient.SqlDataAdapter da =new System.Data.SqlClient.SqlDataAdapter();

da.SelectCommand = sqlcommand;

DataSet ds =newDataSet();

sqlconnect.Open();

sqlcommand.ExecuteNonQuery();

da.Fill(ds);

GridView1.DataSource = ds;

GridView1.DataBind();

sqlconnect.Close();

}

First, make sure the SQL does return data by executing it like it query analyser or management studio.

Try this code in stead

System.Data.SqlClient.SqlConnection sqlconnect =new System.Data.SqlClient.SqlConnection("");//added connection string hereString command ="SELECT * from table";System.Data.SqlClient.SqlCommand sqlcommand =new System.Data.SqlClient.SqlCommand();sqlcommand.CommandText = command;sqlcommand.Connection = sqlconnect;System.Data.SqlClient.SqlDataAdapter da =new System.Data.SqlClient.SqlDataAdapter();da.SelectCommand = sqlcommand;DataSet ds =new DataSet();da.Fill(ds);GridView1.DataSource = ds;GridView1.DataBind();

|||

hi,

I have already checked the query in query builder and it works absolutely fine. The connection also works when i use the SQLDataSource control from the toolbox. However, it does not work with the code. Also, the code that you suggested gives the same output as before.

|||

Hi,

are you mapping the columns in dataview by manually or allow auto generated Columns.

System.Data.SqlClient.SqlConnection conn = new System.Data.SqlClient.SqlConnection(" ");
System.Data.DataSet ds = new System.Data.DataSet();
System.Data.SqlClient.SqlDataAdapter adapter = new System.Data.SqlClient.SqlDataAdapter();
conn.Open();
adapter.SelectCommand = new System.Data.SqlClient.SqlCommand("Select * From Table", conn);
adapter.Fill(ds, "Authors");
conn.Close();

GridView1.DataSource = ds;
GridView1.DataBind();

Hope this Work

|||

sjm:

I have already checked the query in query builder and it works absolutely fine. The connection also works when i use the SQLDataSource control from the toolbox. However, it does not work with the code. Also, the code that you suggested gives the same output as before.

The code should execute fine and as you say there are no errors.

Can you just break through and step over all the code just to make sure no exceptions are being thrown, and also inspect the dataset object after it has been filled to see if datatables/datarows exist in it.

|||

Hey

This does not work either. I've tried mapping the columns manually as well as Allowing auto generate, both don't give the required output.

Do i need to create a new table manually for allowing display of grid view?

if yes, how should i do that?

|||

sjm:

Do i need to create a new table manually for allowing display of grid view?

There is no need. The gridview can be bound to a dataset and it will auto generate the bound fields based on the datatable in the dataset.

Did you step through the code to make sure no errors and thrown and can inspect the dataset?

|||

place ur code in try catch block.

and also check ds.tables[0].rows.count by debug. is should return > 0.

|||

Thanks to all of you who replied...

I could solve the Problem...

The problem with the code was that the columns in the grid were not binded to the data.

I did that nd the code worked..

thank you.