Showing posts with label appsettings. Show all posts
Showing posts with label appsettings. Show all posts

Friday, February 24, 2012

how to use appsettings to connect to the SQL server

Can you tell me how to use Appsettings to connect to the SQL server to retrieve data?

i use:

<appSettings>
<add key="ITR_DW_ConnectionString" value="server=wangjin ; user id=sa ;password=?password?;database=data" />
</appSettings>
But that doesn't work.
how can i get the user id and password?And how should i set the database in SQL server?
thanks a lot !

then i use:
<appSettings>
<add key="ITR_DW_ConnectionString" value="Server=wangjin;Database=data;Trusted_Connection=True;" />
</appSettings>
But during the connection the system reply:
can't log in 'wangjin\ASPNET'
:( what can i do please help.First create your database in SQL Server, lets says DB1 as a name.
Create a login that will have access to that database, let's say log1 and pwd as password.
Your connection string should be something like this:

<add key="ITR_DW_ConnectionString" value="server=servername;user id=log1;password=pwd;database=DB1" /
If you now retrieve the key in your code and put that in the constructor of your connection object (or pass it to the connectionstring property) it should work|||:::( what can i do please help.

RTFM and provide full error descriptions

Btw - for connectionstrings http://www.connectionstrings.com/ has GREAT examples of ALL parameters for basically all databases. Nice shortcut fto answer questions like:

::And how should i set the database in SQL Server

and much faster than trying to find this in the documentation.

::<add key="ITR_DW_ConnectionString" value="server=wangjin ; user id=sa ;password=?
::password?;database=data" /
This SHOULD work, IF you provide a valid password and username. AND if your sql server is actually configured to allow mixed mode or sql server type logins, not just trusted connections / computer accounts.

I suggest you read up on SQL Server security setup in - the sql server documentation. The different modes are quite interesting.

Here:

::<add key="ITR_DW_ConnectionString"
::value="Server=wangjin;Database=data;Trusted_Connection=True;" /
The error message is natural. Trusted connections use the identity of the process making the connection. and wanjin\ASPNET has no rights on the database server, I assume. Pretty standard. You need to change asp.net worker process or use impersonation (lok up the term inthe documentation) if you want to use trusted connections.