I need some opinions and ideas on how to choose and use sql connection string? i do search fom sqlconnectionstring's website, but i tried for few types couldn't work with my network system. can pros out there help me please?
My condition is like below:
I got 1 computer for hosting and i installed sql2008 express server(microsoft sql management studio), and login as window authentication. (ip: 192.168.1.101)
With my created database was with out any security login id and password. (.MDF)
I got another computers work as client to connect and access the hosting computer which hosting the sql server. there ip had set to static (192.168.1.102, 192.168.1.103, 192.168.1.104)
i had tested this connection string but i failed to get connect
Data Source=192.168.1.101,1433;Network Library=DBMSSOCN;
Initial Catalog=myDataBase
I did configure the firewall to allow the 1433 ports which is my sqlserver current using port. Checked sqlserver tcp:enabled, via:enabled, Namepipe:enabled, shareMemory:enabled. Setting of allowed computer remote-able.
So far these are what i configured, but still unable to connect, can anybody guide me?
Maybe because you're using a windows authentication. If you're connecting to SQL server using another computer, the login of that computer should be:
A part of a domain where the server is (i.e. [domain]\myusername).
It should be added to the SQL Server's Security\Login. Go to management studio, then in the object explorer under the server, go to the folder Security\Login. You should see a list of users under login. Your user (other computer's login) should be there.
Now, if you're not part of a domain, you should use a SQL server authentication. I haven't tried using windows authentication in two computers which is not part of a domain.
Related
I create application using C# windows forms which uses local SQL Server database server to store / read data using this connection string:
SqlConnection cn = new SqlConnection("Data Source=localhost;Initial Catalog=mydb;Integrated Security=True");
After that I created a setup file (exe) then I installed the setup file in same PC and the application works well and can read data from the SQL Server database.
Now the problem came when I went to another PC I installed SQL Server and I manually attached the same database (mydb) and installed my application and it did not work. The error is shown in the screenshot:
I have different SQL Server name in the other PC but I specified in the connection string that the SQL Server is Localhost so I don't know why it didn't work. Please help me how to fix this error. Thank you
Make sure Sql Server is set to allow Tcp/Ip connections and that it's set to allow integrated security logins. Then, make sure the user on that machine is granted the correct access to the database. You may have better luck using Sql authentication over Windows Authentication here, if you want to be able to distribute this application and have it "just work".
Finally, if Sql Server here is meant to be a simple datastore for a typical local desktop application, it's probably overkill. Full Sql Server (including Express Edition) is a server engine. It works best when it's the only thing running on the machine and can use up all of the resources on the machine in order to cache data and handle requests from many remote machines. If you just want a local data store for a typical desktop application, an in-process engine like Sql Server LocalDb, Sql Server Compact Edition, Sqlite, or even MS Access would be a much more appropriate choice.
You need to set up Windows authentication for the user that's logged in on the other computer. Because you are using Integrated Security, it will attempt to connect to SQL Server using the windows login of the current user. This will be a different login on different computers, so the SQL Server on the other computer needs to have that user added.
You need to start SQL Server Browser Service. It lets your app connects to SQL Server:
SQL Server Browser listens for incoming requests for Microsoft SQL
Server resources and provides information about SQL Server instances
installed on the computer.
To enable it:
In SQL Server Configuration Manager, go to Properties => Service tab => Start Mode = Automatic.
Or
This computer => Manage => Services and Applications => Services => SQL Server Broswer
Note: You need a sql specific user for connect to it, you can not go with Integrated Security for every machine.
Create a Sql Server user and allow it to access the Database:
--//Creates the login AbolrousHazem with password '340$Uuxwp7Mcxo7Khy'.
CREATE LOGIN AbolrousHazem
WITH PASSWORD = '340$Uuxwp7Mcxo7Khy';
GO
--//Creates a database user for the login created above.
CREATE USER AbolrousHazem FOR LOGIN AbolrousHazem;
GO
Reference
I have two PC (both have Win7). On PC "A" I have installed Microsoft SQL Server 2008 and developed a Windows application. On PC "A" my application is running well and there is no connectivity issue.
But when I run this application on PC "B" (connected with PC "B" through LAN and able to share any file) it shows error message login failed for user'....'.
I have already make some possible solution but can't solve it.. Need help
My connection string is:
Data Source=WIN7-PC\PRABHAT;Initial Catalog=plproject;User ID= win7-PC\Prabhat;MultipleActiveResultsets=true
Is there any problem?
The SQL Server error log contains addtional information about failed logins. Look there and find the code that maps to the table listed here: https://support.microsoft.com/en-us/kb/555332
One possible issue is that you are running as a machine account that doesn't exist on machine B. You need the Windows identity to flow from one machine to another and this is typically accomplished with a domain service account. If you want it to work from machine B, you need to access it with an account machine B is aware of. Supplying the User ID is typically for SQL Server authentication, not Windows authentication. You could try adding the password and see if that works.
Here is a breakdown of SQL Connection String syntax: https://www.connectionstrings.com/sql-server/
You need to enable TCP/IP for cross machine SQL SERVER access. Just follow below mentioned steps to ensure whether it is enable or disabled.
Click on window start menu.
Navigate to Microsoft SQL SERVER => Configuration Tool => SQL
Server 2008 Configuration Manager.
In Opened window Navigate to SQL SERVER Network Configuration =>
Protocols for <MSSQLSERVER> (Protocols for your SQL server
instance name)
Check Whether TCP/IP is enabled or not.
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
I'm currently developing a web application using asp.net c#. I got a server where I today was
going to publish my website and its database. Its a server that runs Windows Server 2008 R2.
But I have one issue:
My website doesn't seem to get access to the database. If I run the website from another computer on my local network I can access the server's database, BUT I can't when I run the website from the same server where the database is. This is really weird. I hope someone can help.
I just get an error that says, it can't access the database.
The most weird of all is that I'm using the same connection string on both computers, but it still doesn't work. Are there maybe some sort of settings in Windows Server 2008?
Here is my connection string:
<add name="ConnectionString"
connectionString="Data Source=AXELS;Initial Catalog=Sailor;Persist Security Info=True;User ID=sa;Password=saab123"
providerName="System.Data.SqlClient" />
Since the connection works on one machine and not on another, I'd guess you have an issue with a firewall or similar - but it will be hard to tell until we see the actual error message. Until then, there are a few things you might want to do:
If it appears as if the connection has to time out before you get the error, it indicates a connectivity problem. Do you have a firewall between the two servers? Does the database server have a firewall that explicitly lets your machine (or internal) machines get through, but hasn't been setup to let the webserver get through? You have to make sure that port 1433 is open on the server.
Are there other sites on the webserver that can connect to the database?
If you have console access to the server, try to set up an ODBC from the server to the database - usually in Control Panel -> Data Sources (ODBC). If you set up a connection with the same DB Server, username and password and test the connection, you might get some pointers to what is wrong.
If the above doesn't provide you with an answer, I'd try to go through the steps described here:
http://blog.sqlauthority.com/2009/05/21/sql-server-fix-error-provider-named-pipes-provider-error-40-could-not-open-a-connection-to-sql-server-microsoft-sql-server-error/
And if that fails, take a look at this - which is apparently only valid when you get SQL Network Interfaces, error: 26
http://blogs.msdn.com/b/sql_protocols/archive/2007/05/13/sql-network-interfaces-error-26-error-locating-server-instance-specified.aspx
This is probably a permission problem.
You need to show us your connection string so we can see how exactly you try to connect to your database.
For example, if you are using Windows authentication, maybe your app runs under different accounts on both machines - and the account on the other computers has permission to access the database, but the account on the database server has not.
Have you checked the if the protocols you are using are enabled on the SQL Server e.g.
C:\Windows\System32\cliconfg.exe -- 64 bit version
C:\Windows\SysWOW64\cliconfg.exe -- 32 bit version
or check SQL Server Configuration Manager 'SQL Server Native Client *' tabs.
This is only applicable if you do not use Windows Authentication, else read the post about priviliges from Christian Specht - in this case I agree.
The fact that you can connect from another PC on the network means that all you database settings, user accounts and permissions are probably set up correct.
It seems there might be a issue with the way the server resolves localhost, as it will try to resolve the Data Source to localhost because AXELS = localhost on that machine.
Have a look at your hosts file and see if there's any funny pointers except for the default.
Located in C:\Windows\System32\drivers\etc
There should be an entry: 127.0.0.1 localhost
I've just finished my c# application with sql database built in 2008 r2 version
I wanted to share this database over LAN and my connection string is :
ConnectionString = #"Data Source=192.168.0.1,1433\SQLEXPRESS;user id=Rula; password=marojo;AttachDbFilename=\\192.168.0.1\Release\WEPA.mdf;Connection Timeout=30;Integrated Security=SSPI;user instance=true";
where 192.168.0.1 is the IP of the computer hosting the sqlexpress instance
when I connect to database locally from the hosting computer I get no errors, but when I try to connect to the database from the shared application I get the following error:
User doesn't have permission to perform this action.
while I mapped the GUEST user to my database on the hosting machine since I knew that if a computer try to connect to database remotly, it connect as guest.
notice: I have my application and database shared over network in the same folder, and again locally everything is ok
Please what can I do to solve this problem ????
thanks in advance =-)
If the 2 machines are not on the same domain this will fail. You might want to use sql logins
The guest account would not be used in an trusted connection. The integrated connection uses the user account attached to the process using the connection string.
http://forums.asp.net/t/822604.aspx/1
If you wanted to use integrated security, the web server would need to be configured to digest logins and then you would need to grant access to all (potential) authenticated users access to the database. This is typically not done due to the unnecessary complexity you are adding to the process. Just use sql links like Ali stated and be done with it.
Okay, I see a couple things that are wrong in your connection string.
Namely, you have defined a user id and password... then you go on to set the Integrated Security flag. These are mutually exclusive. Either it connects as the same user that the app is executing under (most likely the app pool user account) OR it connects as the user defined in your connection string.
The reason you see a difference between 7 and XP is simply that one is defaulting to using the user id / password, the other is defaulting to using integrated security.
I suggest that you visit http://www.connectionstrings.com/ in order to build a proper connection string.
Update:
Other things I see. First, AttachDbFilename can only work with integrated security. Obviously that isn't a possibility, so you need to get rid of that parameter and configure sqlexpress directly on the server to target that database file.
Second, User Instance is for desktop deployments.. not servers. Get rid of it as well because it's going to be a huge memory hog.
Third, read this: http://msdn.microsoft.com/en-us/library/ms247257(v=VS.100).aspx
There are quite a few reasons this could be happening:
SQL Browser service not turned on
Connection string using a trusted connection and you are not set up as that user (check what user your code is using by getting User from the current context)
You do not have the same protocols set up on the client (less likely)
Since it is a permissions issue, you will most likely have to set up your windows domain account in the database to use it. If that is not an option for the application users, then you may desire to move to a sql account rather than windows accounts.
problem solved !!
there was just attaching problem when the database is attached to sql server management studio it's attached as an old name or related to the computer it's copied from
Thank you everyone for your effort : )