SQL Server 2008 R2 connection string - c#

HI people.
I had SQL Server 2005 on Windows XP 32bit and just used this connection string
Server=.\SQLEXPRESS;database=GroupALD; Integrated Security=True"
Now I have Windows 7 64bit and SQL Server 2008 R2 I'm trying to connect database with same string but its shows this error
Cannot open database "GroupALD" requested by the login. The login failed.
Login failed for user 'lester\les'.
Can somebody help me?
I'm using C# and Winforms

Yes, try connectionstrings.com:
Data Source=myServerAddress;Initial Catalog=myDataBase;Integrated Security=SSPI;

The error message is pretty clear:
Cannot open database "GroupALD"
requested by the login. The login
failed.
Login failed for user 'lester\les'.
Your user doesn't have a valid login on your new database - it's not a connection-string related issue - you need to create a login for lester\les on your new server and create a user in the GroupALD database for that login.
See : how to create a SQL Server Login

Can you connect to your express edition using SQL Server Management Studio of R2 ?
One workaround i can suggest is to export the database from express to R2 if you can connect to R2 using your connection string .

Related

Unable connect to SQL Server 2008 R2

I have a C# project with SQL Server 2008 R2 and the project runs with no problem on my local machine and when I publish it to the server Win2008 R2. But the project doesn't work and can't connect to the server with no error. All the database setting check and I enabled TCP/IP setting and etc. But still not worked. I think the problem is with connection string that is below.
When pages going to connect to the database, nothing happened in browser and browser stick in loading mode (waiting for respond).
Connection string on my computer
Data Source =(Local);Initial Catalog=Bulk;Integrated Security=True;Timeout=0;Max Pool Size=5000;
Connection string on Windows server
Data Source=My Ip Windows Server,1433;Network Library=DBMSSOCN;Initial Catalog=Bulk;User ID=administrator;Password=My Windows Login Pass;Timeout=0;Max Pool Size=5000;
I got this error:
A network-related or instance-specific error occurred while
establishing a connection to SQL Server. The server was not found or
was not accessible. Verify that the instance name is correct and that
SQL Server is configured to allow remote connections. (provider: SQL
Network Interfaces, error: 26 - Error Locating Server/Instance
Specified
In your connection string of Server you have:
Data Source=My Ip Windows Server,1433;Network Library=DBMSSOCN;
To connect via IP Address and Port of 1433 and over TCP/IP protocol
Initial Catalog=Bulk;
Bulk is your database name
User ID=administrator;Password=My Windows Login Pass;
Authenticate via SQL Server connection by administrator login user and its password.
I think your problem is in third part that you want to connect to SQL Server by your Windows user name; You can see valid logins of your SQL Server in Security branch of your registered server in SQL Server Management Studio that will shows your Windows user name like Domain Name\User Name so you need to change User Id to that.
Configure the Windows Firewall to Allow SQL Server Access. open port 1433 in windows firewall.
see this link. Or this.
Please Try to connect in your local Sqlserver With Live Login Detail,
If you are Success Then There should be Permission Need to set From the Live Hosting Server
if is it possible then please add the More specification.
You should log the errors that occur, e.g. in Application_Error if it's actually an ASP.Net project.
Using the log you should get errormessages that hint you or enable you to give more details so nobody has to guess what your actual issue is.
Regarding your issue:
Did you give your Windows account the necessary READ/WRITE access on SQL Server?
On MS SQL Server the account needs access to:
1. Be added to the general Security/Logins for an actual match of Windows account to Login.
2. Be added to the specific database Security/Users tab with the necessary database role membership.
In addition to specifiying your Windows account + password in the connectionstring: maybe it's better to run the application pool using a service-account and use
Integrated Security=True
and remove
User ID=administrator;Password=My Windows Login Pass;
I have changed my connection string to this and problem solved.
public static string ConnectionString = "Data Source=My Ip,1433;Initial Catalog=My DataBase;UID=sa;Pwd=My Pass;Timeout=0;Max Pool Size=5000;";
In sql server management studio
Click "Security" => "Logins" => "sa" right-click and click properties
in the left side click "Status" and in the right side,Choose enable in login

Connect with SQL Server 2008 Express using Winforms (C#)

I am creating the database from coding in Winforms (C#) and also run the script for creating the tables.
In short I create the database using the Winforms (C#) in SQL Server Express.
But when I run my application I get this error :
Cannot open database '' requested by the login. the login failed. login failed for user 'KETAN\admin'.
My connection string:
Server=.\SQLEXPRESS;Integrated Security=True;database=mydatabasename;User Id=myusername;Password=mypassword;
Any help would be appreciated.
If you have both
Integrated Security=True;
and
User Id=myusername;Password=mypassword;
in your connection string, then the Integrated Security wins and the specific user and password are ignored, and the connection is attempted with your current Windows credentials (KETAN\admin) and that doesn't seem to work
So just change your connection string to:
Server=.\SQLEXPRESS;database=mydatabasename;User Id=myusername;Password=mypassword;
Now, your specific user and its password will be used to connect to SQL Server, and if those are correct, you should be able to connect just fine

Cannot connect from c# to sql locally but can remotely

I have a c# application i want to connect it to sql server , the server and the application are used on the same machine , but I application cannot connect to the sql however if I installed the application on another machine and keeping the server in the first server they are connected !
The server is installed on windows 8.
Thanks
Please do the following -
Make sure your local database server has both Windows Authentication and SQL Server Authentication mode enabled. But
If you are using Windows Authentication then change the connection string to -
connectionString="Data Source=LENOVO;Initial Catalog=APP;Integrated Security=True;"
If you are using SQL Server authentication mode, which it seems since you are providing username yourself then
connectionString="Data Source=LENOVO;Initial Catalog=APP;Integrated Security=False;User ID=sa;Password=111"
Also, APP is usually a reserve keyword in some systems. Its better to avoid such name as the name of the DB.
If you are using default server instance you can use . or (local) instead of LENOVO
Check that the firewall is not preventing you from connecting.

How to access sql server 2008 R2 from C# ClickOnce application over a network

I've a clickOnce C# application that works fine on a standalone computer. i wanted to use the application over the network but the system fails to connect to the sql server (SQL SERVER 2008 R2) and throws an exception. I've created a user on the sql server and assigned it on the connection string of the application. However, the problem still persists. Any help please?
Check your connection string on your app
check:
Connection strings for SQL Server 2008
Configure your SQL server security as sql server and windows authentication mode.
Make sure its instance is running.
Create sql server authentication login if your app will be use on network.
Regards

Accessing sql 2008 database through visual studio 2010 C#

Hey guys I have what should be a simple question, but I am new to C# so I am having just a little problem. I am using the following connection:
SqlConnection conn = new SqlConnection(#"Server=myservername\SQLEXPRESS;Database=Names;");
I have also tried to include user id and password but my login always fails.
I think this is because I am not really sure what username and password to use.
With my sql server I am using windows authentication... if that helps.
does anyone know which username and password I should be using? or another way to do this?
I have seen that I may need to turn remote access on in my sql settings, can anyone tell me how to do that?
Thanks!
Your connection string should specify that integrated authentication (Windows authentication) has to be used. Otherwise it tries to do SQL user/password authentication, which is disabled on the SQL Server by default, and if enabled it doesn't authenticate against Windows users.
Server=.\SQLEXPRESS;Database=YourDatabaseName;Integrated Security=SSPI;
Remote access is only required if your application and the SQL Server Express instance aren't on the same machine (which is why the sample connection string here has a . for the server name, which represents the local server).

Categories

Resources